in reply to Regarding Declaring Variables
Each <STDIN> reads a line from stdin so if you have:
my $var = <STDIN>; while ($var = <STDIN>)
you read a line in the declaration (my $var), then replace the value in the while loop while ($var = <STDIN>).
The next;s inside the elsifs bypass the print "Enter ... at the end of the loop.
For fun consider this version:
use strict; my $target = 12; print "Guess my number.\n"; while ((print "Enter your guess: "), my $guess = <STDIN>) { (print "You guessed it!"), last if $guess == $target; (print "You guessed too low\n"), next if $guess < $target; (print "You guessed too high\n"), next if $guess > $target; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regarding Declaring Variables
by Delusional (Beadle) on Nov 17, 2005 at 09:42 UTC | |
by GrandFather (Saint) on Nov 17, 2005 at 19:40 UTC | |
by ysth (Canon) on Nov 18, 2005 at 12:36 UTC |