http://www.perlmonks.org?node_id=436414


in reply to To Pattern Match or not to Pattern Match

In your else block, you need to add 'last;' to exit the inner loop and go to the next element in the outer loop.
else { print "Name does not exist\n"; last; }
That should prevent that line from printing 10 times.
--------------------
mlh2003

Replies are listed 'Best First'.
Re^2: To Pattern Match or not to Pattern Match
by Anonymous Monk on Mar 04, 2005 at 00:14 UTC
    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.