in reply to Plain old bad code

What's with the

for ( 1 .. $i ) { my $line = `head -$_ $filename | tail -1`; print $line; }

As any fule no, that should be written as

my $line; my $ln = 0; for ($ln = 1; $ln <= $i; $ln = $ln + 1) { system ("head -$_ $filename | tail -1 > file.tmp"); open(FILE, "file.tmp"); my $tmp = $_; while (<FILE>) { chomp; print $_; print "\n"; } close FILE; $_ = $tmp; }

I'm very proud of the masterful technique used to avoid clobbering $_

• another intruder with the mooring in the heart of the Perl

Replies are listed 'Best First'.
Re^2: Plain old bad code
by richill (Monk) on May 28, 2006 at 23:01 UTC
    Could you explain to a newbie what do you mean by clobbering $_ and why that is bad?