Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Need to return the first occurance of a search

by kennethk (Abbot)
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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1029376]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2018-06-23 08:52 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (125 votes). Check out past polls.