Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: grep with multiple choice

by agianni (Hermit)
on Jun 11, 2007 at 16:19 UTC ( #620526=note: print w/replies, xml ) Need Help??


in reply to grep with multiple choice

A couple of map statements should make this pretty easy to do with an array:

my @array = map { chomp and $_ } <DATA>; my $want = 'Julia_Roberts'; my $change = 'Cintheia'; my ( $suffix ) = map { m/\A$want(\(\S+\))\z/smx and $1 } @array; my @final = map { ( /\A($change)\z/ and "$change$suffix" ) or $_ } @ar +ray if $suffix; warn Dumper \@final; __DATA__ Julia_Roberts(1,5) Cintheia Chelsia Rohan

The first map statement goes through the array and identifies the suffix for the pattern to be matched and the second applies the suffix to the desired element. I would probably do some kind of error checking after the first map, getting an array instead of a scalar from the map and checking to see if there's only one element returned -- what do you do if Julia_Roberts(1,5) and Julia_Roberts(2.8) are in the list?

perl -e 'split//,q{john hurl, pest caretaker}and(map{print @_[$_]}(joi +n(q{},map{sprintf(qq{%010u},$_)}(2**2*307*4993,5*101*641*5261,7*59*79 +*36997,13*17*71*45131,3**2*67*89*167*181))=~/\d{2}/g));'

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2022-11-30 16:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?