In the following code, the second call to use_hash fails:
use strict;
use warnings;
$|=1;
sub empty_list {
@{ [] }
}
sub use_hash {
my (%h) = @_;
print(join(',',keys %h),"\n");
}
use_hash(foo1 => undef, bar1 => 5);
print "not defined\n" unless defined ((empty_list)[0]);
use_hash(foo2 => (empty_list)[0], bar2 => 5);
The ouput of the program is as follows:
bar1,foo1
not defined
Odd number of elements in hash assignment at C:\tmp\emptylist_a.pl lin
+e 12.
foo2,5
We see that the first
use_hash works. We also see that (not surprising) an empty list indexed by [0] yields undef. I would have expected the 2nd call to
use_hash being the same as the first: Instead of passing
undef<c> explicitly to key <c>foo2, I "generate" it by taking the first element of an empty list. However, the latter does not work.
--
Ronald Fischer <ynnor@mm.st>
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.