On Nov 26, 2010, at 1:10 PM, Téssio Fechine wrote: > > 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" } > > } > [snip]
> > 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? The third "when" is causing a string comparison, not a regular expression. 'Frederick' is not stringwise-equal to 'Fred', so the test fails, and you proceed into the default. The hidden "break" (like the explicit "continue") is only executed if the enclosing when-clause matches. Otherwise, you just proceed to test the next case - or into the default, as the case may be. Regards, Chap -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/