I'm not sure if this is a bug or not. I'm running perl 5, version 26, subversion 1 (v5.26.1) built for MSWin32-x64-multi-thread from Strawberry Perl.
If I have a %hash, I can pass it to a function with \%hash.
In the function, I can assign elements by autovivification:
$$hash{'key1'}{"$var2"} = $value;
or
$$hash->{'key1'}->{"$var2"} = $value;
BUT, and this is the real issue, if I want to print all the 'var2's, I must do something (still in the function) like:
foreach $key (keys %$hash{'key1'}->%* ){
print "$key\n";
}
Omitting the ->%* produces an error "Experimental keys on scalar is now forbidden" and if I omit the leading % it says the global symbol $hash is not defined. Perl version 5.24 is when the ->%* was supposed to be a nearly 1:1 compatible replacement for %$ dereferencing (and no longer experimental), and as far as I know there's probably not supposed to be a circumstance where you need BOTH.
After further testing, with the $${}{} assignment I can get the keys inside the function using %{ $$hash{'key'} } or $$hash{'key'}->%* . Is there an explanation for the referencing/syntax going on?
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.