Steve said:
Hi all,
I have not posted here before. I am compelled to ask about this code
snipet crashing perl.exe when attempting a perl -c:
#!/usr/bin/perl -w
use strict;
sub &total {
my $sum;
foreach (@_){
sum+=$_;
}
Basically I know the code is bad, but I never expected perl to crash on a
syntax check. Should I send this bug somewhere or just not write bad code?
Thanks!
Steve
Doesn't crash perl 5.8.4 on my Debian Linux machine (standard sarge build):
syscjm@ayato:~$ perl -c perltest.pl
Illegal declaration of anonymous subroutine at perltest.pl line 4.
syscjm@ayato:~$
Doesn't crash perl 5.8.5 on my SPARC Solaris 9 machine (sunfreeware, I
think...):
$ perl -c perltest.pl
Illegal declaration of anonymous subroutine at perltest.pl line 4.
$
Doesn't crash perl 5.6.1 on the Solaris box (shipped with Solaris):
$ /usr/perl5/5.6.1/bin/perl -c perltest.pl
syntax error at perltest.pl line 4, near "sub &total"
Can't use global @_ in "my" at perltest.pl line 6, near "(@_"
Missing right curly or square bracket at perltest.pl line 8, at end of line
Bareword "sum" not allowed while "strict subs" in use at perltest.pl line 7.
perltest.pl had compilation errors.
$
Doesn't crash perl 5.005_03 on the Solaris box (also shipped with Solaris):
$ /usr/perl5/5.00503/bin/perl -c perltest.pl
syntax error at perltest.pl line 4, near "sub &total"
Can't use global @_ in "my" at perltest.pl line 6.
$
I could look over at a couple of AIX boxes I have access to, but that's
probably enough...
Perhaps it's just a problem with your build (something around 5.6, maybe,
I think I saw somebody else reporting this bug in a 5.6.x build...)
However, for future reference, no program should ever crash; it
should report the error (whatever it was) and handle it gracefully
in the most appropriate manner. A program crash is *always* a bug,
although it may not be a fixable one (for example, it is very
difficult to keep a program from crashing if you run your computer
out of memory to the point where the program can no longer
successfully do a malloc(); unless the program itself is doing the
memory chomping, this is not really fixable).
--
Christopher Mattern
"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"