bug in perl concerning arrays?

Jonathan Sweedler cjosta at tasu77.UUCP
Sun Jul 2 16:50:51 AEST 1989


I am running perl on a Sun 3/60 with SunOS 3.5.  The version is:
$Header: perly.c,v 2.0.1.10 88/11/22 01:14:58 lwall Locked $
Patch level: 18

I have the following perl program:

#!/usr/local/bin/perl
@directory = @ARGV;
--$#directory;
print $#directory;

This should set the array 'directory' equal to all of the command line
arguments except the last one.  But, the last line in the perl program
always prints out '-1' and the array is left null.  If I change the 
'--$#directory' line to be '$#directory = $#directory - 1'
or if I put the line 'print $#directory' before the '--$#directory'
line then the program works.  It seems I must reference the '$#directory'
variable before I can use change it.  

Am I doing something wrong here?  Or is this a bug in perl?

Jonathan Sweedler  ===  National Semiconductor Israel
UUCP:    ...!{amdahl,hplabs,decwrl}!nsc!taux01!cjosta
Domain:  cjosta at taux01.nsc.com



More information about the Comp.sources.bugs mailing list