DavidSzczesniak
12/13/2017 - 11:37 AM

References

A Perl reference is a scalar data type that holds the location of another value that could be a scalar, array or hash. The basics are explained here.

# To create a reference for any variable, subroutine or value, prefix it with a backslash:
$scalarref = \$foo;
$arrayref = \@ARGV;
$hashref = \%ENV;
$coderef = \&handler;
$globref = \*$foo;

\!h # NOTE: Any changes made to a reference will change the original value in place (i.e its main purpose)

# A reference to an anon array can be made using square brackets:
$arrayref = [1, 2 ['a', 'b', 'c']];

# Similarly, you can create a reference to an anon hash with curly brackets:
$hashref = {
  'Adam' => 'Eve',
  'Clyde' => 'Bonnie',
};

# Referencing an anon subroutine can be done using sub without a subname:
$coderef = sub{print "Boink!\n"};