#!perl -w
use strict;use warnings;
use Switch;
sub Main {
Switch {print "hi\n";return;}
}
and glory be got
hi
Why, i dunno?
ok it wasnt that simple. first i tried
#!perl -w
use strict;use warnings;
use Switch;
Switch {my $a=1};
and got
Can't locate object method "Switch" via package "1" (perhaps you forgo
+t to load "1"?) at switch.pl line 4.
Thinking that all those returns were the reason i went to
#!perl -w
use strict;use warnings;
use Switch;
Switch {my $a=1;return};
and got
Can't return outside a subroutine at switch.pl line 4.
AHAH, the reason for the sub Main {}
so i cant figure out what Switch {} is doing. there is no sub Switch in Switch.pm (there is a sub switch tho). I figure it has something to do with use Filter::Util::Call and the import and filter subroutines. Can anyone give me a clue?
edit:fixed case in "Can't locate switch.pm" from a typo/wrong-copy-paste
edit2: ok i think i got it if a class is used to invoke the method, that argument will be the name of the class.http://docstore.mik.ua/orelly/perl/prog3/ch12_03.htm. so Switch {} is trying to invoke method Switch with an argument (without parens) that is the result of a block, but the block "never ends?" due to the return. Is that it? |