I'd split up the foreach loop and the conditional....

it might be a little clunky, but here's the basic idea.....

bolFound = false

foreach (@members) {
   if (/($enqmem)/i) {
      bolFound = true;
      }
   }

if (bolFound) {
   do stuff
   }
else {
   do other stuff
   }

At 18:54 27-03-02 +0000, Wytch wrote:
>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]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to