in reply to Re: This code is just freaky...
in thread This code is just freaky...
won't go to the while it's next to, but the outer foreach loop. Thus, you don't enter an infinite loop.foreach my $a (1 .. 5) { next while ($a != 2); }
A curious thing was that I wrote the quick program:
How does the range-op-boolean know that $s was a in a previous check. It seems to be maintaining state between invocations.my @strings = ('a', 'b', 'c', 'd', 'e', 'f'); while (my $s = shift @strings) { print "Looking at $s\n"; next while ($s =~ /a/ .. $s =~ /c/); print "$s is OK!\n"; }
Update:
This gives a very interesting output.my @strings = ('a', 'b', 'c', 'd', 'e', 'f'); while (my $s = shift @strings) { print "Looking at $s\n"; my $value = $s =~ /a/ .. $s =~ /c/; print "The value is $value\n"; next if $value; print "$s is OK!\n"; }
I just find that '3E0' thing really odd...Looking at a The value is 1 Looking at b The value is 2 Looking at c The value is 3E0 Looking at d The value is d is OK! Looking at e The value is e is OK! Looking at f The value is f is OK!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: This code is just freaky...
by John M. Dlugosz (Monsignor) on Jul 27, 2001 at 22:47 UTC | |
|
Re: Re: Re: This code is just freaky...
by petral (Curate) on Jul 29, 2001 at 12:41 UTC |