Gotcha
(or maybe a 'got-me'?) that jumped up and bit me.
Of course, if I had had warnings on... it would have been simpler to see what was going on, ... but then on the other hand, I would not have seen this fun stuff:
#!/usr/bin/perl use strict; #use warnings; for my $i (1 .. 20) { isodd($i); print "$i\n"; } sub isodd { my $i = shift; next if int($i/2)*2 == $i; return; }
gives:
1 3 5 7 9 11 13 15 17 19
Perl is so cool, but so dangerous without warnings!
Needless to say, after some refactoring, my 'next' was in a different module than my loop, and I couldn't figure out why bits of code were not being executed as expected.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using next inappropriately inside a sub
by roboticus (Chancellor) on Mar 29, 2006 at 02:07 UTC | |
|
Re: Using next inappropriately inside a sub
by DrHyde (Prior) on Mar 29, 2006 at 09:45 UTC | |
by salva (Canon) on Mar 29, 2006 at 10:00 UTC | |
by ambrus (Abbot) on Mar 29, 2006 at 13:12 UTC | |
by merlyn (Sage) on Mar 29, 2006 at 14:19 UTC |