heman has asked for the wisdom of the Perl Monks concerning the following question:
Hi Guys,
I'm writing a perl program to get an array of numbers/charaters and add the number but when the character "q" or "Q" if received it should exit.
print "Enter a array of any number of elements \n"; @x=<>; chomp @a; print "@x \n"; foreach(@x) { if(($_>0)&&($_<21)) { $y+=$_; print "Inside sum logic $_\n"; } elsif(($_ eq "q")||($_ eq "Q")) { print "Inside last $_ \n"; last; } }
but for some reason i don't see my check for "q" or "Q" getting true! Can somebody suggest what could be the problem?
Thanks :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: simple perl program not working
by GrandFather (Saint) on Oct 15, 2014 at 22:21 UTC | |
|
Re: simple perl program not working
by AnomalousMonk (Archbishop) on Oct 16, 2014 at 00:22 UTC | |
|
Re: simple perl program not working
by karlgoethebier (Abbot) on Oct 16, 2014 at 09:09 UTC |