Referencing anonymous data

It is also possible to take references to literal data not stored in a variable. This data is called anonymous because it is not bound to any named variable.

To create a reference to a scalar constant, simply backslash the literal string or number.

To create a reference to an anonymous array, place the list of values in square brackets:

$shortbread = [ "flour", "butter", "eggs", "sugar" ];

This creates a reference to an array, but the array is available only through the reference $shortbread.

A reference to an anonymous hash uses braces around the list of elements:

$cast =  { host     => "Space Ghost",
           musician => "Zorak",
           director => "Moltar" };

Get Perl in a Nutshell, 2nd Edition 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.