Although I'd recommend using further arrows other wise you'll get your knickers in a twist.
Remember that % means a whole hash, and $ is a hash value (as it is in effect a scalar).
So if $hashref contained a hash, then you could access the whole hash with %$hashref (the hash % in the scalar reference $hashref).
Remember references (or pointers if you will) are a single value (a single reference), so effectively a scalar, hence the $.
Use arrow notation and the appropriate brackets to access the nested hash/array you need.
$hashref = \%hash; # $hashref is a scalar pointing to %hash
%$hashref or %{$hashref}# the same as %hash
$hash{'key'}
# is the same as
$hashref->{'key'}
$hashref->{'key'} = \@array; # Make this key a reference to the array
+@array
@{$hashref->{'key'}} # the same as @array, the extra brackets {} show
+you are looking for the array in $hashref->{'key'} and not an array i
+n $hashref
$hashref->{'key'}->[0] # same as $array[0]
It takes a little getting used to, but all makes sense after a while.
The books Advanced Perl Programming (First Edition) and Intermediate Perl cover this quite well
Lyle
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.