Skip Menu |

This queue is for tickets about the Switch CPAN distribution.

Report information
The Basics
Id: 14327
Status: resolved
Priority: 0/
Queue: Switch

People
Owner: Nobody in particular
Requestors: lallip [...] cs.rpi.edu
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 2.10
Fixed in: (no value)



Subject: Syntax error in switch block used in prototyped-subroutine
This (short-but-complete) script works as expected: #!/usr/bin/perl use strict; use warnings; use Switch; sub foobar ($\%) { my $foo = shift; my $hash_ref = shift; switch ('hello'){ case (/^[A-Z]+$/) { print "All upper\n"; } case (/^[a-z]+$/) { print "All lower\n"; } else { print "Mixed case\n"; } } } my %temp; foobar('world', %temp); __END__ All lower If, however, I switch the order of the prototyped arguments to the subroutine, I get a syntax error involving the switch block: #!/usr/bin/perl use strict; use warnings; use Switch; sub foobar (\%$) { my $hash_ref = shift; my $foo = shift; switch ('hello'){ # <== LINE 9 case (/^[A-Z]+$/) { print "All upper\n"; } case (/^[a-z]+$/) { print "All lower\n"; } # <== LINE 11 else { print "Mixed case\n"; } } } my %temp; foobar(%temp, 'world'); __END__ syntax error at switchtest.pl line 9, near "){" syntax error at switchtest.pl line 11, near ") {" Execution of switchtest.pl aborted due to compilation errors. This seems to occur only when the prototype involves a \% , and that \% appears as anything but the last element in the prototype list. If the \% is last, the script parses correctly. I have seen this behavior on both perl 5.8.5 for Solaris and Activestate's perl 5.8.4 for Windows, both using Switch.pm v2.10. Another poster to c.l.p.m. confirmed it on perl 5.8.7 built for MSWin32-x86-multi-thread, Switch 2.10. I regret that I don't know anywhere near enough about source filtering to begin creating a patch for this issue.
Date: Sat, 05 Nov 2005 11:25:09 -0800
To: bug-Switch [...] rt.cpan.org
Subject: Re: [cpan #14327] Syntax error in switch block used in prototyped-subroutine
From: Damian Conway <thoughtstream [...] gmail.com>
RT-Send-Cc:
Show quoted text
> sub foobar (\%$) { > my $hash_ref = shift; > my $foo = shift; > switch ('hello'){ # <== LINE 9 > case (/^[A-Z]+$/) { print "All upper\n"; } > case (/^[a-z]+$/) { print "All lower\n"; } # <== LINE 11 > else { print "Mixed case\n"; } > } > > } > > my %temp; > foobar(%temp, 'world'); > > __END__ > > syntax error at switchtest.pl line 9, near "){" > syntax error at switchtest.pl line 11, near ") {" > Execution of switchtest.pl aborted due to compilation errors.
Fixed in the next release. Thanks! Damian