On 26/11/2010 19:10, Téssio Fechine wrote:
I think this is a bug:
tes...@krauzer:~/Perl/Ex/ch15$ cat when
#!/usr/bin/perl -w
use 5.010;
use strict;
given($ARGV[0]) {
when(/fred/i) { say 'Name has fred in it'; continue }
when(/^Fred/) { say 'Name starts with Fred'; continue }
when('Fred') { say 'Name is Fred' }
default { say "I don't see a Fred" }
}
tes...@krauzer:~/Perl/Ex/ch15$ ./when Fred
Name has fred in it
Name starts with Fred
Name is Fred
tes...@krauzer:~/Perl/Ex/ch15$ ./when Frederick
Name has fred in it
Name starts with Fred
I don't see a Fred
tes...@krauzer:~/Perl/Ex/ch15$
As you can see, the 'default' was not supposed to say anything in the
second time the program is run, with the argument "Frederick".. The
last 'when' is supposed to have a hidden "break", right? So what's
wrong?
Yes, but the last 'when' isn't executed because 'Frederick' doesn't
equal 'Fred'. Neither the say nor the implicit break are executed and
execution falls through to the default condition.
HTH,
Rob
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/