Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: On patterns and more

by perliff (Monk)
on Mar 09, 2011 at 13:09 UTC ( [id://892184]=note: print w/replies, xml ) Need Help??


in reply to On patterns and more

Ok, let me rewrite your code for you in a simpler way... You want to match in the "second" name if I get it right.. avoiding matching people who might be called Jackson Anything or Jackson Something or perhaps, even just jackson. I have put comments in the code itself.
my @myNames = ('Larry jackson', 'Curly jackson', 'Moe Sanders','Jackso +n Something','jackson',); # our list of names, note that I added a few more print "Who's on the list:\n"; foreach $fullname (@myNames) { # $fullname contains each name in @myNames one by one @array = split (/\s+/,$fullname); # lets split the name based on a whitespace character, # in our case, a space, \s if (scalar @array > 1) { # if the number of elements in the array @array # is more than one, which it should be, then # check the second element, like this if($array[1] =~ /jackson/i) { # the "i" indicates a case-insensitive match, # Jackson is same as jackson print "$fullname\n"; # go ahead and print } } }

perliff

----------------------

-with perl on my side

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (8)
As of 2024-04-23 12:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found