Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Re: opening a file destroys nulling entries in a list?!?!

by IlyaM (Parson)
on Aug 07, 2003 at 07:15 UTC ( [id://281778]=note: print w/replies, xml ) Need Help??


in reply to Re: opening a file destroys nulling entries in a list?!?!
in thread opening a file destroys nulling entries in a list?!?!

Somehow, the aliasing of the input to $_ is getting mixd up with the first element of @_

When you do screwed($_) variable $_ gets aliased to $_[0] inside screwed() as subroutine parameters always aliased to elements of @_ array inside the subroutine. So later when while loop modifies $_ it affects $_[0] too.

Shorter demo:

$_ = 1; test($_); sub test { $_ = 2; print $_[0], "\n"; } # output of script __END__ 2
Yet another example why I think while(<>) { ... } considered harmful.

--
Ilya Martynov, ilya@iponweb.net
CTO IPonWEB (UK) Ltd
Quality Perl Programming and Unix Support UK managed @ offshore prices - http://www.iponweb.net
Personal website - http://martynov.org

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (1)
As of 2024-04-24 14:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found