Saturday, December 20, 2008

Creating an Anonymous Reference

Perl developers sometimes have the need to pass information to functions by reference. Perl offers developers the ability to create references to anonymous arrays and hashes. This enables Perl developers the ability to create some very complex data structures.

Use the following syntax to manufacture anonymous arrays and hashes in your programs:

# Use brackets to create an anonymous array
$aref = [ "Nashville", "Chattanooga", "Knoxville", "Memphis" ]; # manufactures a *new* anonymous array

# Use braces to create an anonymous hash
$href = { "Nashville" => "Music City", "Memphis" => "BBQ Capital" }; # manufactures a *new* anonymous hash

No comments: