Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: Need to return the first occurance of a search

by kennethk (Monsignor)
on Apr 18, 2013 at 15:19 UTC ( #1029376=note: print w/ replies, xml ) Need Help??

in reply to Need to return the first occurance of a search

I have been trying grep and regular expresions, but my regex is not up to solving this particular problem.
What in particular did you try, and what didn't work? Effort demonstrated through posted code is generally taken as a sign of good faith.

It's fairly simple to test for the existence of a particular string, say cups-1.5.2-9.fc16.x86_64, but what is your intended behavior when the version number changes? My solution might look something like

perl -e '@arr=`rpm -qa`; if (grep /^cups-\d/, @arr) {print grep /^cups +-\d/, @arr} elsif (grep /^cups-/, @arr) {print "Empty set\n"}'

Expanding it to handle other leading strings would be easy, though in the general case you may want to escape the string, e.g. /^\Q$name\E-\d/

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Comment on Re: Need to return the first occurance of a search
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2014-08-22 04:29 GMT
Find Nodes?
    Voting Booth?

    The best computer themed movie is:

    Results (146 votes), past polls