sleepingsquirrel has asked for the wisdom of the Perl Monks concerning the following question:
Taking a reference to an enumerated list is not the same as using square brackets--instead it's the same as creating a list of references!The special case talks about returning a list of references to the contents of @foo, but it seems more like it returns a reference to a list (whose contents are copied from @foo). It Did What I Meant in the original code, but the documentation seems a little fuzzy to me. Further illumination appreciated.As a special case, \(@foo) returns a list of references to the contents of @foo, not a reference to @foo itself. Likewise for %foo, except that the key references are to copies (since the keys are just strings rather than full-fledged scalars).@list = (\$a, \@b, \%c); @list = \($a, @b, %c); # same thing!
#!/usr/bin/perl -w use Data::Dumper; $ref=\(1..3); $enum_list_ref=\(1,2,3); @a=(\(1..3),\(5..9)); print "\n".Dumper($ref)."\n"; print "\n".Dumper($enum_list_ref)."\n"; print "\n".Dumper(\@a)."\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: list references
by Enlil (Parson) on Jun 15, 2004 at 22:07 UTC | |
by sleepingsquirrel (Chaplain) on Jun 15, 2004 at 23:41 UTC | |
|
Re: list references
by BrowserUk (Patriarch) on Jun 15, 2004 at 22:13 UTC | |
|
Re: list references
by NetWallah (Canon) on Jun 15, 2004 at 23:02 UTC | |
by sleepingsquirrel (Chaplain) on Jun 15, 2004 at 23:48 UTC | |
by NetWallah (Canon) on Jun 16, 2004 at 16:01 UTC |