Anonymous References

The references that we have seen thus far have been to variables that have already had storage allocated for them.

@data = (10,20,30,40);       # allocate the array
$rdata = \@data;             # create a reference to it
%states = (                  # allocate a hash
            MD => Annapolis,
            CA => Sacramento,
            NY => "New York City"
          );
$rhash = \%states;           # create a reference to it

In some cases you will want to take another approach; that is, you will want to create a reference to anonymous storage.

Anonymous Arrays

The syntax for an anonymous array uses the [ ] operator. When Perl sees this operator in the following context, the address of the data within the [ ] is created. In the code below, $refa is simply a reference to an array. It can be used as before. The ...

Get Programming PERL in the .NET Environment now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.