in reply to On patterns and more
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
|
|---|