-----Original Message-----
>From: Owen Chavez [mailto:owen.chavez314...@gmail.com] 
>Sent: Thursday, September 30, 2010 2:41 AM
>To: beginners@perl.org
>Subject: Alternative to while ()
>
>Hey y'all,
>
>I suspect that I'm struggling with something that has a *really*
>straightforward alternative, but I don't do a lot of programming in perl
(or
>any other language, really), and I can't see it.
>
>I've got a block of code that I'd like to run in a loop until a user enters
>some desired input.  My question is what control structure I should be
using
>for greatest efficiency and clarity?  What I'm using now is something like
>this:
>
>while () {
>     if ($input = 'this') {
>          # Do some things.
>          last;
>     }
>     elsif ($input = 'that') {
>          # Do some other things.
>           last;
>     }
>     else {
>          print "The original directions again.\n";
>          chomp ($input = <STDIN>);
>     }
>
>Keeping the conditional statement empty and using last gets the job done,
>although I know it's not right (even if it is effective).  Can someone
nudge
>me in the right direction?
>
>-Owen.

Hi,
I addition to Uri's comments, let me add that you should have these two
lines at the top of your script:

Use strict;
Use warnings;

If you had these, you would have been warned that you are using the
assignment operator (=) instead of the conditional operator ( 'eq' for
strings, '==' for numbers ).
Ken




-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to