Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Plain old bad code

by grinder (Bishop)
on May 20, 2006 at 10:10 UTC ( [id://550658]=note: print w/replies, xml ) Need Help??


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?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-23 18:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found