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

Re: Storing Lines before and After pattern

by jweed (Chaplain)
on Jan 27, 2004 at 01:00 UTC ( #324324=note: print w/replies, xml ) Need Help??


in reply to Storing Lines before and After pattern

Because of $` and $' overhead, this is an ideal place for split:
open ($fh, "<poem") or die "Couldn't Open!"; $poem = do{ local $/; <$fh> }; ($before, $match, $after} = split /(DOG)/, $poem;



Code is (almost) always untested.
http://www.justicepoetic.net/

Replies are listed 'Best First'.
Re: Re: Storing Lines before and After pattern
by ysth (Canon) on Jan 27, 2004 at 01:09 UTC
    If there may be multiple occurrences of DOG, you want:
    ($before, $match, $after) = split /(DOG)/, $poem, 2;
    or $after will only include up to the second DOG.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2022-01-22 23:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (63 votes). Check out past polls.

    Notices?