Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re^4: perl array of hashes help

by ragilla (Novice)
on May 07, 2013 at 04:20 UTC ( #1032435=note: print w/replies, xml ) Need Help??

in reply to Re^3: perl array of hashes help
in thread perl array of hashes help

Hi Trizen,

I have one question regarding access of the perl hash key which is an array reference like below i have an hash

 my $all = {'text' => [                                      'HJ0039_x.pdf' , 'HJ0039' , 'HJ0039'                                      ]};

To access the above elements i can use two ways like below

 print " $all->{text}[0] ;


 print "${$all->{text}}[0]

can you please explain me clearly what is the difference between the above two methods , without de-referencing the array how we are able to access the array elements


Replies are listed 'Best First'.
Re^5: perl array of hashes help
by trizen (Hermit) on May 07, 2013 at 22:41 UTC
    Hello Ragilla,

    The code $all->{text}[0] is equivalent with $all->{text}->[0]. This implies an implicit dereference. Similar with $array_ref->[0].

    In the second code, ${$all->{text}}[0] is similar with $array[0], because $all->{text} is an ARRAY REF, and @{ARRAY_REF} is similar with @array, which can lead to ${ARRAY_REF}[index].

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1032435]
[Corion]: Heh - a good talk on Youtube about why you want to keep your Genome as secret as possible (and not use it for vanity stuff like 23andme , or some ancestry stuff)

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2018-01-19 18:17 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (222 votes). Check out past polls.