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

help on searching an array

Thread Next
From:
Wytch
Date:
March 27, 2002 10:57
Subject:
help on searching an array
Message ID:
20020327185437.6264.qmail@onion.perl.org
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



Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About