Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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.

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 scrutinizing the Monastery: (3)
As of 2016-02-06 14:41 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (231 votes), past polls