![]() |
|
Think about Loose Coupling | |
PerlMonks |
Re: question about $_ and eofby wmono (Friar) |
on Mar 13, 2002 at 08:05 UTC ( #151328=note: print w/replies, xml ) | Need Help?? |
Ah, welcome aboard, wageslave! To answer your question about $_, you can read that variable as "it". When you write something like print $_, you are saying "print it". You can, as you've discovered, leave the "it" out, and Perl will know what you mean. As for the problems you're having in your three code snippets, here's a quote from perldoc -f eof to get us started:
What I'd like to point out from there is that eof is not a value, but rather a function. So when you do <STDIN>!=eof, you compare <STDIN> with either true or false. That's not something that's very printable, or something that makes a lot of sense. This is also why your second loop doesn't work. Also, again from perldoc -f eof, I present the following snippet:
Perl has a very practical view on what is true or false. When you do while (<STDIN>), you will stop when <STDIN> returns undef, which is considered false. Keeping all of this in mind, here's how I might re-write your loop:
Alternatively, I might write:
Good luck in your adventures!
In Section
Seekers of Perl Wisdom
|
|