Beefy Boxes and Bandwidth Generously Provided by pair Networks kudra
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Better way to get the results of grep()?

by eye (Hermit)
on Dec 09, 2009 at 19:44 UTC ( #812017=note: print w/ replies, xml ) Need Help??


in reply to Better way to get the results of grep()?

Rather than using an intermediate array and saving its first element, you could save the first element from the list that grep produces.

($curFrom) = grep(/^From:/, @header); ($curSubject) = grep(/^Subject:/, @header);
Note that using the 'o' modifier on the regular expression does not offer a benefit in this instance. It is only useful when the regular expression would be re-evaluated on each execution (as when it includes a variable).


Comment on Re: Better way to get the results of grep()?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2014-04-20 14:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls