Surprisingly, I can use next within a sub to be able to fall thru to the next case, which leads to a nice syntax.
use strict; use warnings; use diagnostics; sub switch { no warnings 'exiting'; while (@_) { my ($case, $action) = splice @_,0,2; return $action->($case) if $_ ~~ $case; } } #no warnings 'exiting'; switch [1,2,3] => sub { print "bla" ; next}, 3 => sub { print "bla2" } for (3);
But I'm getting
Exiting subroutine via next at d:/Users/RolfLangsdorf/pm/switch.pl lin +e 18 (#1) (W exiting) You are exiting a subroutine by unconventional means, +such as a goto, or a loop control statement.
Obviously I can't dynamically disable the warning, because it's lexically scoped.
Uncommenting the #no warnings 'exiting' works, but would be acting for a much wider scope.
Is it possible to disable a certain warning in the dynamic scope?
Overwriting the warn handler does the trick ...
local $SIG{__WARN__} = sub { warn "$_[0]" unless $_[0] =~ /^Exiting subroutine via next/ } ;
... , but maybe there is a cleaner solution?
NB: this is experimental code and not meant for production! :)
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Wikisyntax for the Monastery
In reply to Disabling runtime warnings in dynamic scope? by LanX
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |