euswdwj has asked for the wisdom of the Perl Monks concerning the following question:
Having thought that one might be close to obtaining variable scope master in Perl such strange happenings presented today.
A while loop that never exits:
#!/usr/bin/perl use strict; while ( my $number != 10 ) { printf("Please, the number 10: "); $number = <STDIN>; }
A program that does not compile:
#!/usr/bin/perl use strict; while ( $number != 10 ) { printf("Please, the number 10: "); $number = <STDIN>; }
A while loop that works as expected:
#!/usr/bin/perl use strict; my $number; while ( $number != 10 ) { printf("Please, the number 10: "); $number = <STDIN>; }
While it is not my usual practice to program on a Wednesday, I have done so today. Could that be the reason or is there an other?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Variable scope in while loop
by davido (Cardinal) on Dec 19, 2012 at 22:18 UTC | |
|
Re: Variable scope in while loop
by frozenwithjoy (Priest) on Dec 19, 2012 at 22:18 UTC | |
|
Re: Variable scope in while loop
by tobyink (Canon) on Dec 19, 2012 at 22:19 UTC | |
|
Re: Variable scope in while loop
by Athanasius (Archbishop) on Dec 20, 2012 at 02:37 UTC |