Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Grep is changing the original list?

by merlyn (Sage)
on Apr 17, 2001 at 20:46 UTC ( #73238=note: print w/replies, xml ) Need Help??

in reply to Grep is changing the original list?

perldoc -t -f grep yields (in part)...
Note that, because $_ is a reference into the list value, it can be used to modify the elements of the array. While this is useful and supported, it can cause bizarre results if the LIST is not a named array. Similarly, grep returns aliases into the original list, much as a for loop's index variable aliases the list elements. That is, modifying an element of a list returned by grep (for example, in a foreach, map() or another grep()) actually modifies the element in the original list. This is usually something to be avoided when writing clear code.

-- Randal L. Schwartz, Perl hacker

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2021-09-28 03:28 GMT
Find Nodes?
    Voting Booth?

    No recent polls found