Perl crashes

S

Steve Butler

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
 
A

A. Sinan Unur

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?

C:\Home\asu1> perl -v

This is perl, v5.8.4 built for MSWin32-x86-multi-thread
(with 3 registered patches, see perl -V for more detail)

....

C:\Home\asu1> perl -c t9.pl
Illegal declaration of anonymous subroutine at t9.pl line 4.

Sinan.
 
J

Jürgen Exner

Steve said:
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?

Good catch. Does it repro with the latest perl version?
It does on my machine, but I am still running 5.6.1 which is a bit outdated
and definitely not the right reference platform.

If this bug is repro in the latest version, then see "perldoc perlbug".

jue
 
J

James Tolley

#!/usr/bin/perl -w
use strict;

sub &total {
my $sum;
foreach (@_){
sum+=$_;
}

This just needs a little editing:

#!/usr/bin/perl -w
use strict;

sub total {
my $sum;
foreach (@_){
$sum+=$_;
}
$sum;
}

print total(1,2,3); # 6
__END__

hth,

James
 
C

Chris Mattern

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?"
 
J

Joe Smith

James said:
This just needs a little editing:

Correcting the typo is not the point.
The point is that perl should output
"Illegal declaration of anonymous subroutine at temp line 4."
and not crash.
-Joe
 
J

Jim Keenan

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?

One more data point:

[perl 505]$ perl -v

This is perl, v5.8.4 built for darwin-2level


[perl 506]$ test1.pl
Illegal declaration of anonymous subroutine at
/Users/jimk/bin/perl/test1.pl line 5.
 
S

Steve Butler

Thanks for the feedback all! I sent in a bug via perldoc perlbug last night.

I neglected to mention my platform being windows xp. Sorry for any
confusion. Here is the perl -v loved by all:

E:\My Projects\perl\chapter 6>perl -v

This is perl, v5.6.1 built for MSWin32-x86-multi-thread
(with 1 registered patch, see perl -V for more detail)

Copyright 1987-2001, Larry Wall

Binary build 638 provided by ActiveState Corp. http://www.ActiveState.com
ActiveState is a division of Sophos.
Built Apr 13 2004 19:24:21

Perl may be copied only under the terms of either the Artistic License or
the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'. If you have access to the
Internet, point your browser at http://www.perl.com/, the Perl Home Page.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top