Here's one way. Instead of printing out the confirmation right away, I stored a 1 in the $ismem variable if one of the matches was true. Then I used it later to check if any of the names had matched. Another way would be to use a hash instead of an array so that you can check the index against the hash keys.
@members=qw( June Hilda Brian Ashley Shaun Isobel Susan Bob Emma ); $g1="Hello"; $info="You asked for information on"; $end="Thankyou for your enquiry"; print "What is your name: "; chomp($enqname = <STDIN>); print "What member would you like information on: "; chomp($enqmem=<STDIN>); print "$g1 $enqname. $info $enqmem.\n"; foreach (@members) { if (/($enqmem)/i) { $ismem = 1; } } if($ismem){ print "$1 is a member of our club.\n"; }else{ print "Unfortunately $enqmem is not a member of our club!\n"; } print "Thankyou for your enquiry."; -----Original Message----- From: Wytch [mailto:[EMAIL PROTECTED]] Sent: Wednesday, March 27, 2002 10:55 AM To: [EMAIL PROTECTED] Subject: help on searching an array Hi, I am new to this list and to Perl. I decided after years of promises to my self that I would finally tackle programming. I started reading up on it and think I have got the basics but I am still very much a Perl virgin! I decided to try to write a little script [no practical application just an exercise] that allows you to search a club member list and be informed as to whether the person is a club member or not. The problem is that it works fine if they are a member but doesn't inform you if they are not. I am sure the answer is simple but I may well have fried my brain on all the code and just can't see it. Where have I gone wrong? #!c:/perl/perl.exe @members=qw( June Hilda Brian Ashley Shaun Isobel Susan Bob Emma ); $g1="Hello"; $info="You asked for information on"; $end="Thankyou for your enquiry"; print "What is your name: "; chomp($enqname = <STDIN>); print "What member would you like information on: "; chomp($enqmem=<STDIN>); print "$g1 $enqname. $info $enqmem.\n"; foreach (@members) { if (/($enqmem)/i) { print "$1 is a member of our club.\n"; } elseif (/ne($enqmem)/i) #this is the problem area #if I use 'else' it outputs for each member { #when I only want one output print "Unfortunately $enqmem is not a member of our club!\n"; } } print "Thankyou for your enquiry."; it seems that I can code for a positive but can't figure out the negative - does that make sense?? lol If anyone can shed any light on this I would appreciate it. Wytch -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -------------------------------------------------------------------------------- This email may contain confidential and privileged material for the sole use of the intended recipient. If you are not the intended recipient, please contact the sender and delete all copies. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]