Hello colleagues,
I am in the process of "enhancing" someone else's code. There is an array of hashes and I need to be able to reference an array element in it - the hash. I tried something like that:
#!/usr/bin/perl my @array; $array[0]{'key'} = "testline"; $item = \$array[0]; $array[0]{'key2'} = "testline2";
However, the $item can not be properly dereferenced for some reason. Here is the debugger session:
[me@system directory]$ perl -d aht.pl Loading DB routines from perl5db.pl version 1.19 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(aht.pl:2): my @array; DB<1> b 5 DB<2> c main::(aht.pl:5): $array[0]{'key2'} = "testline2"; DB<2> p $array[0]{'key'} testline DB<3> p $array[0] HASH(0x8086ab4) DB<4> p $$item HASH(0x8086ab4) DB<5> p $$item{'key'} Not a HASH reference at (eval 10)[/usr/lib/perl5/5.8.0/perl5db.pl:17] +line 2. DB<6> q [me@system directory]$
As one can see, $item is a proper reference, but it needs a cast of some sort. My experiments were unsuccessful - anyone have a hint?
Sincerely,
Vlad.
In reply to Reference to a hash in an array of hashes by vlad
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |