in reply to Re: Re: Re: regex issue
in thread regex issue
On the first iteration, it checks /2/ against $_, which contains 0, so it returns false and nothing is printed. On the second iteration, same thing, except $_ contains 1. On the third iteration however, $_ contains 2 so /2/ matches and the construct returns true and it prints. It keeps printing numbers untill $_ matches /5/.for(0..10) { if(/2/../5/) { print; } }
Note that the check to set $flag to 0 is *after* the print statement. This is because the construct returns true the first time the right hand side also returns true. It of course returns false after that.my $flag; for(0..10) { if(/2/) { $flag = 1; } print if $flag; if(/5/) { $flag = 0; } }
|
|---|