Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Re: question about $_ and eof

by rinceWind (Monsignor)
on Mar 13, 2002 at 11:31 UTC ( #151346=note: print w/replies, xml ) Need Help??


in reply to Re: question about $_ and eof
in thread question about $_ and eof

Just to clarify one point about
while (<STDIN>)
Q: Why does this not stop on a blank line?

A: <STDIN> is returning a newline character '\n', which is true. In practice, regardless of O/S, you never get the empty string or a bare 0, hence the only false value you encounter is undef.

Replies are listed 'Best First'.
Re: Re: Re: question about $_ and eof
by strat (Canon) on Mar 13, 2002 at 12:36 UTC
    > A: <STDIN> is returning a newline character '\n', which
    > is true. In practice, regardless of O/S, you never get
    > the empty string or a bare 0, hence the only false value
    > you encounter is undef.

    I think, the construct while (<STDIN>) { is just another way to write:  while (defined ($_ = <STDIN>)){, not only for while ($_ = <STDIN>) {.

    The difference is not big; only if there is a 0 (=zero) on the last line of a file without \n, it can become essential. But with pure STDIN this case might never happen, only with files or the like...

    Best regards,
    perl -le "s==*F=e=>y~\*martinF~stronat~=>s~[^\w]~~g=>chop,print"

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://151346]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (1)
As of 2023-09-21 19:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?