Petruchio has asked for the wisdom of the Perl Monks concerning the following question:
The Switch module is a nifty thing, IMO. It's a source filter, molesting your code in strange and unspeakable ways to provide the answer to all those Chatterbox prayers... a switch statement in Perl. Saith merlyn in On Parsing Perl, "Perl is extremely difficult to parse. In fact, some would say impossible." But the author, Damian Conway, seems to be trying very hard to parse Perl in Perl.
Switch does not, however, work quite properly...
Quite so. I sent the good Doctor a (rather strange) bug report, and in his reply he said,
If you want to patch your own copy immediately, change line 91 from:
$text .= substr($source,$pos[2],$pos[18]-$pos[2]);
to:
$text .= " " . substr($source,$pos[2],$pos[18]-$pos[2]);
Conway gave me permission to share this fix and others he might send. I suggest that if you're using the module, you do this now.
Anyway, I found another bug, as strange as the first. When I reduced my code to this:
#!/usr/bin/perl -w use strict; use Switch; my $x = 2 ? 'foo' : 'bar'; switch('x'){ case 'y' {print "y\n"} else {print "x\n"} } # ?
it generated the following errors:
Bareword "case" not allowed while "strict subs" in use at ./Shell.pl l +ine 9. Unquoted string "case" may clash with future reserved word at ./Shell. +pl line 9. String found where operator expected at ./Shell.pl line 9, near "case +'y'" (Do you need to predeclare case?) syntax error at ./Shell.pl line 9, near "case 'y'" Execution of ./Shell.pl aborted due to compilation errors.
Funny thing is, if you remove either the trinary operator, or the question mark in the final comment, the program works.
Conway replied:
I can't replicate this bug, but it seems to be an old Perl parsing problem. Are you sure you have the latest version of Text::Balanced installed?
In fact, I do; $VERSION = '1.83'; interestingly, in the POD for *this* module Conway says, "There are undoubtedly serious bugs lurking somewhere in this code".
I am, however, still using perl 5.005_03. To be more specific, perl -V says:
Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration: Platform: osname=linux, osvers=2.2.15pre14, archname=i386-linux uname='linux them 2.2.15pre14 #2 smp mon mar 13 14:29:00 est 2000 +i686 unknown ' hint=recommended, useposix=true, d_sigaction=define usethreads=undef useperlio=undef d_sfio=undef Compiler: cc='cc', optimize='-O2 ', gccversion=2.95.2 20000313 (Debian GNU/L +inux) cppflags='-Dbool=char -DHAS_BOOL -D_REENTRANT -DDEBIAN -I/usr/loca +l/include' ccflags ='-Dbool=char -DHAS_BOOL -D_REENTRANT -DDEBIAN -I/usr/loca +l/include' stdchar='char', d_stdstdio=undef, usevfork=false intsize=4, longsize=4, ptrsize=4, doublesize=8 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=1 +2 alignbytes=4, usemymalloc=n, prototype=define Linker and Libraries: ld='cc', ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib libs=-lnsl -lndbm -lgdbm -ldbm -ldb -ldl -lm -lc -lposix -lcrypt libc=, so=so, useshrplib=false, libperl=libperl.a Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynami +c' cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib' Characteristics of this binary (from libperl): Built under linux Compiled at Apr 30 2000 12:08:38 @INC: /usr/lib/perl5/5.005/i386-linux /usr/lib/perl5/5.005 /usr/local/lib/site_perl/i386-linux /usr/local/lib/site_perl /usr/lib/perl5 .
Which should pretty well clue you in as to my setup. Anyway, I'd like to solicit a little help; if you could run my little script on a platform unlike my own and report the result, as well as the output of perl -v, I'd appreciate it. You'll need to edit what you get from d/l code a bit, since I've been obliged to use code tags for formatting the snippets, too. And, naturally, don't forget to apply the aforementioned patch.
I strongly suspect Conway is running a newer version of perl than I am, and I expect to find the answer there... but I cannot say for certain.
Thank you!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Help Debug Switch.pm!
by btrott (Parson) on Apr 23, 2001 at 10:35 UTC | |
(jeffa) Re: Help Debug Switch.pm!
by jeffa (Bishop) on Apr 23, 2001 at 09:34 UTC | |
(tye)Re: Help Debug Switch.pm!
by tye (Sage) on Apr 23, 2001 at 18:40 UTC | |
Re: Help Debug Switch.pm!
by grinder (Bishop) on Apr 23, 2001 at 12:15 UTC | |
Re: Help Debug Switch.pm!
by jmcnamara (Monsignor) on Apr 23, 2001 at 12:13 UTC | |
Re: Help Debug Switch.pm!
by Brovnik (Hermit) on Jun 14, 2001 at 13:58 UTC |