I have a function that takes a reference to hash as a
parameter. This has has one element that's a reference to
(multidimensional) array. Now, I tamper a lot with that
array and the form
$$hash{arraykey}[$i][$j] notation is
a bit tiresome compares to
$array[$i][$j], not to mention
that other uses such as @{$$hash{arraykey}} can get pretty
confusion. So, I figured, why not alias them? We have this
local() function here just for that (amongst other things...),
right? After some pretty confusing warnings, here's a testbed
I used to track down the problem. It's not pruned enough
to get to the core, but close enough, I suppose.
%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 ?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.