Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: modify list through grep

by Sidhekin (Priest)
on Nov 26, 2006 at 15:30 UTC ( [id://586112]=note: print w/replies, xml ) Need Help??


in reply to modify list through grep

grep returns aliases, but assignment (to @m) makes copies. You can not modify the grep results directly though, so you need to do something like take a reference, pass it to a (naughty) sub, or make a modifiable alias in order to modify the alias, and not just a copy thereof:

@l = ( "a", "b", "c" ); $_ = "z" for grep /a/, @l; print @l;

Prints "zbc".

print "Just another Perl ${\(trickster and hacker)},"
The Sidhekin proves Sidhe did it!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-04-24 21:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found