Anonymous Monk has asked for the
wisdom of the Perl Monks concerning the following question:

My question to you perl experts is this: would it be possible to assign a particular result if it doesnt find a match? Would it be better to use something else besides the matching operator? Is there an operator to state if nothing matches? I have a list of users stored in an array called @names(20 names) in this format "MANDERSON/Anderson MikeD|MikeD.Anderson\\". @cdwv_list has a list of 10 names stored with this format "MANDERSON". Here is an example of the code:

for ($j = 0; $j < @cdwv_list; $j++) {
$user_id = $cdwv_list[$j];
foreach $names(@names) {
if ($names =~ $user_id) {
#if match I want it to grab name
$names =~ /\/([\w\s]+)\|/;
$name = $1;
}
#So what do I put here or somewhere else if
#the 1st $name doesnt match any of the 10
#users from @cdwv_list? I tried:
else {
#But it only prints this 10 times
#even thought only 1 name doesnt
#match between the two list
print "Name does not exist\n";
}
}
}

Try #2: I just realized what you're expecting it to do. You have nested loops, and your test is inside the innermost loop. So it's going to run 20 times (inner loop) for each of the 10 names (outer loop).

The "operator to state if nothing matches" might be grep. Something like:

Roy Johnson, thanks for your help. The code works exactly like what I needed. Thanks to everyone else that responded. If I had any sort of pts or anything to give you guys I would. I greatly appreciate the help. --Thomas

I think the problem here is that it loops through the 1st 10 names in @names and since none of those 10 matches it prints out "Name does not exist" 10 times. I need it to loop through all 20 strings in @names and if it doesnt find a match then print "Name does not exist" only once, buts only my guess.