onslaught has asked for the wisdom of the Perl Monks concerning the following question:
I'm confused by the error since when I access the element ${$harry{$k}}$acount this works fine, but if I substitute $k for the value contained in $phash{$k} then the value is apparently uninitialised. I know this can't be the case as $b prints fine so I'm wondering if there is something I'm missing with regards to accessing array elements in a hash of arrays? Thanks in advance for any help and sorry if it's something really simple I'm missing.foreach $k (keys %harry) { $acount = 0; $bcount = 0; if (exists($phash{$k})) { foreach $a(@{$harry{$k}}) { foreach $b(@{$harry{$phash{$k}}}) { if ($a eq $b) { print "$b\n"; #this works as I expect print "$a\n"; #this works as I expect print "${$harry{$phash{$k}}}[$bcount]\n"; #this returns error Use of uninitialized #value in concatenation (.) or string print "${$harry{$k}}[$acount]\n"; #this works as I expect delete ${$harry{$phash{$k}}}[$bcount]; delete ${$harry{$k}}[$acount]; $deletions = $deletions +2; } $bcount = $bcount +1; } $acount = $acount +1; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Accessing (deleting) array elements in a hash of arrays
by jwkrahn (Abbot) on Sep 21, 2008 at 23:41 UTC | |
|
Re: Accessing (deleting) array elements in a hash of arrays
by ysth (Canon) on Sep 22, 2008 at 00:49 UTC | |
|
Re: Accessing (deleting) array elements in a hash of arrays
by jethro (Monsignor) on Sep 21, 2008 at 23:56 UTC | |
|
Re: Accessing (deleting) array elements in a hash of arrays (scalability)
by ikegami (Patriarch) on Sep 22, 2008 at 02:58 UTC | |
|
Re: Accessing (deleting) array elements in a hash of arrays
by sflitman (Hermit) on Sep 21, 2008 at 23:59 UTC | |
|
Re: Accessing (deleting) array elements in a hash of arrays
by toolic (Bishop) on Sep 22, 2008 at 02:03 UTC | |
|
Re: Accessing (deleting) array elements in a hash of arrays (looping over indexes)
by ikegami (Patriarch) on Sep 22, 2008 at 02:33 UTC | |
|
Re: Accessing (deleting) array elements in a hash of arrays
by gone2015 (Deacon) on Sep 22, 2008 at 10:07 UTC |