in reply to Re: A perverse use of grep
in thread A perverse use of grep

IMO the expanded style is bad form:

while ( defined( $_ = <$in> ) )

should be written

while (<$in>) {
---
$world=~s/war/peace/g

Replies are listed 'Best First'.
Re^3: A perverse use of grep
by itub (Priest) on Jun 15, 2005 at 17:20 UTC
    I would also recommend localizing $_, because while doesn't do it automatically:
    sub whatever { local $_; while(<$in>) { # do stuff } }

    Even if the loop is not in a sub, localizing $_ can prevent nasty bugs if you decided to wrap the loop in a sub later.

Re^3: A perverse use of grep
by dragonchild (Archbishop) on Jun 15, 2005 at 12:01 UTC
    You're right ... I originally had while (defined( my $line = <$in> )) and never got rid of the expanded form when I went back to $_. Updated.

    • In general, if you think something isn't in Perl, try it out, because it usually is. :-)
    • "What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against?"