Recently I faced an unexpected perl5's behaviour.
This simple and valid code
#!/usr/bin/perl
use POSIX;
use strict;
use Switch;
sub foo($) {
switch($_[0]) {
case /ACK/i {
return "ACK";
}
case /NACK/i {
return "NACK";
}
}
}
1;
failed to execute due to
syntax error at ./test.pl line 8, near ") {"
syntax error at ./test.pl line 15, near "}"
Bareword "case" not allowed while "strict subs" in use at ./test.pl line 12.
Bareword "NACK" not allowed while "strict subs" in use at ./test.pl line 12.
Execution of ./test.pl aborted due to compilation errors.
If we change foo's prototype requirement to expect more than one scalar
parameters, or drop any requirements - everything will cure and work just
as expected. IOW, case with one scalar parameter is kind of special (read broken).
This turned out to be known problem (#39861, according to Perl5's bugzilla )...
Since around 2004. Only one thing remains to write - WTF?
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment