Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Perl seems to ignore the inner parens, 1 is printed and $hash{'2'} is assigned to 3. I'm trying to get a list inside a hash without requiring any extra variables. Is this possible? I tried%hash = (name => foo, list => (1, 2, 3)); @array = $hash{list}; foreach(@array){print "$_\n";}
but Perl dies on "Not an ARRAY reference". So, is there any way to put a nameless array inside a hash element without any extra variables? Any help is appreciated.%hash = (name => foo, list => \(1, 2, 3)); $ref = $hash{list} @array = @$ref; foreach(@array) { print }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Array inside hashes
by perlmonkey (Hermit) on Jul 22, 2000 at 11:48 UTC | |
|
Re: Array inside hashes
by atl (Pilgrim) on Jul 22, 2000 at 11:50 UTC | |
|
RE: Array inside hashes
by athomason (Curate) on Jul 22, 2000 at 14:03 UTC | |
by Anonymous Monk on Jul 22, 2000 at 22:35 UTC | |
by Anonymous Monk on Jul 22, 2000 at 22:33 UTC | |
|
(kudra) RE: Array inside hashes
by kudra (Vicar) on Jul 22, 2000 at 11:55 UTC | |
by Russ (Deacon) on Jul 23, 2000 at 07:15 UTC |