deferencing a perl reference #my take

This is based on perlreftut’s excellent “Use Rule 1”.

1) To get a reference on a scalar/array/hash, put a “\” in front of the $/@/%
2) To dereference a reference, surround it with
${…..} —————————- eg: ${$a}
@{…..} —————————- eg @{$b}
%{…..} —————————- eg %{$h}

==================The longer version=================
1) To get a reference on a scalar/array/hash or even a filehandle or subroutine, put a “\” in front of the complete variable — complete with those funny characters
\$a
\@b
\%c

Prefixing is cleaner and simpler than dereferencing.

2) Think of a listRef $ref holding a string “items”. @{$ref} becomes @{items}. This is actually a real scenario, known as symbolic reference.
In other words, You can always use an array reference, in curly braces, in place of the name (without titles like “@”) of an array. The titles like “@” were left there by your predecessor before you arrived in your curly braces.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s