171

References & Structures
What is a Reference?

  • A reference is a scalar value which "points to" any variable

  • References to named variables are created using the the unary \ operator (much like the & operator in C)

      $myReference = \$myScalar;
      $myReference = \@myList;
      $myReference = \%myHash;

  • References to named variables are dereferenced using the the scalar $ operator

      print "myScalar = ", $$myReference, "\n";
      print "myList = ", @$myReference, "\n";
      print "myHash = ", %$myReference, "\n";