Just to be extremely explict, "print STDOUT;" is
the same as "print STDOUT $_;". Both of these statements
print the value of the special Perl variable, $_, to STDOUT. Similarly, "print OTHER;", which is the same as
"print OTHER $_;", prints the value of $_ to the "OTHER" file. | [reply] |
print;
suffices. STDOUT is assumed if no file handle is provided. However I used print STDOUT; in the sample code to maintain consistency with the OP's sample code.
The important thing for Grundle is to be aware of $_ and where it is used as the default.
DWIM is Perl's answer to Gödel
| [reply] [d/l] [select] |
Ahh ++ I wasn't aware of that. That seems to be a sloppy way of doing things in my mind, even though it is a quicker shorthand.
In any case I do not see where $_ is ever being set. Running the code myself it comes up empty for every iteration. The data that he wants to operate on is stored in his 2-D Array $list[][]. It makes complete sense that nothing is sent to his files because $_ is empty.
Thanks for pointing out my mistake ;) Although I know about $_ I rarely use it. I find it more readable to explicitely name my variables, and it aids in maintainability for future changes. | [reply] [d/l] [select] |
You have to know about and use $_ if you use map, grep or for (as a statement modifier) and for various common Perl idioms. If you are not using map, grep or statement modifiers then you are missing out on some major workhorses in Perl.
In the op's situation I agree that using a variable is likely to make the intent clearer, but there are a multitude of problems with the code apart from that.
DWIM is Perl's answer to Gödel
| [reply] |