Perl: the Markov chain saw | |
PerlMonks |
Re: Perl Code Changes Behavior if Two Subroutine definitions are swappedby Athanasius (Archbishop) |
on Jul 27, 2016 at 16:05 UTC ( [id://1168656]=note: print w/replies, xml ) | Need Help?? |
Hello rkabhi, As haukex says, the Switch module is deprecated and therefore best avoided. But the problem here is not with the module, but rather with the way it is being used. First, by giving the switch statement an empty argument, you are matching against the empty string:
Output:
You need to specify the string to be matched against: in this case, switch ($_) {. Second, the next statements in your case clauses do not force another iteration of the enclosing while loop, as you expect. That’s because the Switch module uses next to implement fall-through, as explained in the “Allowing fall-through” section of the Switch documentation. You could avoid this by specifying an explicit target for the next statements; for example (untested):
Hope that helps,
In Section
Seekers of Perl Wisdom
|
|