You got the wrong algorithm. Try doing it with grep. perldoc -f grep foreach (@members) { if ( grep { #put your test/check here } @members ){ # they are a member } else { # they aren't } }
> -----Original Message----- > From: Wytch [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, March 27, 2002 1:55 PM > 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] > ---------------------------------------------------------------------------- -------------------- The views and opinions expressed in this email message are the sender's own, and do not necessarily represent the views and opinions of Summit Systems Inc. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]