I started to wondering about this a while ago. There was once a post, which reported his/her discovery that Perl 5.8 has a bug on supporting subs running on its own thread, and returning array or hash. The problem is that the hash or array would be evaluated as if in a scalar context. (Well, there is a workaround, just to return ref to hash or array. In your mind, this workaround is actually even better, as by returning ref, you gain performance quite significantly.)
Now back to my question. When you evaluate array in a scalar context, for example:
@a = (1,2,4,6,8);
$a = @a;
print $a;
It gives you a FIVE, which is quite easy to understand, as it matches $#a.
However, if you do,
%a = (a=>1,b=>2,c=>4,d=>6,e=>8);
$a = %a;
print $a;
It gives you 5/8. Now I don't understand, what does this number or fraction or whatever mean?
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.