http://qs1969.pair.com?node_id=620526


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));'