Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re:^2 Oooh, Oooh, Help Me Help Me (:)

by ChemBoy (Priest)
on Oct 28, 2001 at 09:11 UTC ( [id://121799]=note: print w/replies, xml ) Need Help??


in reply to Re: Oooh, Oooh, Help Me Help Me (:
in thread How can I make a regex apply to each line of a file?

No, please don't use grep that way, unless you actually want to strip lines out of your input if they don't match the substitution pattern. Use map, instead--that's what it's for.

@footerfile = map {s/something/else/} <FILE>;

Note that the first solution proposed using grep wouldn't have the undesired side-effects, but it's still bad coding practice--never use grep or map in void context (obfuscatory and inefficient).

And Kage, please find a better descriptive title for your question next time...

Update: or, of course, you could alter the array in place after reading it in, using

s/nothing/something/ for @footerfile;

Update 2: of course, it would help if I told you the right syntax for map, too...

@footerfile = map {s/something/else/;$_} <FILE>;
(thanks, Zaxo! And I wish I had as good an excuse as jj808 for screwing this one up....)



If God had meant us to fly, he would *never* have given us the railroads.
    --Michael Flanders

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-03-29 02:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found