develooper Front page | perl.beginners | Postings from March 2002

help on searching an array

Thread Next
March 27, 2002 10:57
help on searching an array
Message ID:
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?

@members=qw( June Hilda Brian Ashley Shaun Isobel Susan Bob Emma );

$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: ";

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
                                                                   #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.


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About