Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: Style, style, style

by Aristotle (Chancellor)
on Sep 08, 2002 at 12:24 UTC ( [id://196006]=note: print w/replies, xml ) Need Help??


in reply to Re: Style, style, style
in thread Style, style, style

while (<FH>) is "shorthand" for: while (defined( $_=<FH>)), and the defined can sometimes be important if your last entry in a file is a 0 without \n afterwards. And normally, I don't want to miss a single zero at the end which could even happen with <> if you pipe in a file.
Good worry, but no need to lose sleep since Perl's behaviour has been adapted to do the right thing in the real world a while ago.
$ perl -MO=Deparse -e'1 while my $line = <>;' '???' while defined(my $line = <ARGV>); -e syntax OK $ perl -v This is perl, v5.6.1 built for i386-linux
I'm not sure exactly when it changed; perldoc perldelta for 5.6.1 doesn't mention it and I can't seem to find any mention in older versions of the POD found on perldoc.com either. Of course even on older Perls, you can use the my construct by simply adding the defined yourself..
while(defined(my $line = <>)){ # ... }

Makeshifts last the longest.

Replies are listed 'Best First'.
Re3: Style, style, style
by blakem (Monsignor) on Sep 08, 2002 at 17:55 UTC
    A most obscure bug discusses the "implied defined" feature, its history, and a bug in its implementation that we caught.

    -Blake

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-19 05:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found