kaatunut has asked for the wisdom of the Perl Monks concerning the following question:
%hap=( 'foo' => "hip", 'bar' => [ 2, "blah", ], ); hum(\%hap); print "$hap{foo} $hap{bar}[0] $hap{bar}[1]\n"; sub hum { local *hash=$_[0]; local *array=$hash{bar}; print "$hash{foo} $array[0] $array[1] / @array\n"; # print "$hash{foo} @array\n"; $hash{foo}="gaa"; $array[1]=5; }
Now, see the print lines in sub hum. On my perl 5.6.0, the form I just pasted works fine, whereas commenting the first print out and uncommenting the second gives
In string, @array now must be written as \@array at ./test2.pl line 17, near "} @array"
Now, the only difference is that I use values inside that @array before using the @array itself. Did I get something about local() wrong here, or is that a genuine bug? And do you have any comments on how I should go on with aliasing @{$$_[0]{bar}} to @array ?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: local() peculiarities
by merlyn (Sage) on Jan 22, 2001 at 07:09 UTC | |
by kaatunut (Scribe) on Jan 22, 2001 at 22:55 UTC | |
by chipmunk (Parson) on Jan 22, 2001 at 23:03 UTC | |
|
Re: local() peculiarities
by japhy (Canon) on Jan 22, 2001 at 08:43 UTC | |
by chipmunk (Parson) on Jan 22, 2001 at 09:22 UTC |