Seems to be a popular question for newcomers to ask how to access some component of a complicated structures.
The answer is to user the built-in debugger.
tlegrady@rw-q318:~$ perl -d t.pl Loading DB routines from perl5db.pl version 1.3 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(t.pl:5): my $data = [ DB<1> n main::(t.pl:16): my $test = $data->{ name }; DB<1> x $data 0 ARRAY(0x70b910) 0 HASH(0x70b970) 'name' => 'Mary' DB<2> x $data->[0] 0 HASH(0x70b970) 'name' => 'Mary' DB<3> x $data->[0]{name} 0 'Mary'
When the debugger starts, it shows that it's about to execute line 5. I do a "next" ( 'n') to complete that, and then it's going to execute line 16. I query the debugger to show the value of $data, and then of its components. Since you're looking right at it, it's easy to tell you want array element '0', hash tag 'name'.
As Occam said: Entia non sunt multiplicanda praeter necessitatem.
In reply to Re: Access to hash ref element
by TomDLux
in thread Access to hash ref element
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |