I came across a piece of code, which was provided to demonstrate a limitation when using the each() function:
#!/usr/bin/perl %couples = ( george => gracie, abbot => costello, johnson => boswell ); foreach $c (each %couples) { print "$c\n"; };
The captioned text accompanying this code reads:
"It's important to rember with each() that it will give you only the next key/value pair from the named hash. The output should contain two lines of text, one for george, one for gracie."
In fact, this code produces for me, on my unix system, the following output:
abbot costello
My first question is whether the information in the text regarding the expected code output is erroneous or is it, perhaps, a cross-platform issue, since this was originally DOS code?
My other question is, what is the minimum code that would, indeed print out the names of all three couples and overcome the supposed limitation of the each() function?
Thanks!
In reply to code that fails to act as expected... by cgmd
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |