CaptainPinko
Jul 17th, 2002, 08:46 PM
I'm not sure if this is a bug or my misunderstanding of the Perl syntax. I'm having problems with using references.:(
sub printArray {
my @array = @($_[0]);
my $prefix = (defined $_[1])? $_[1]: "";
foreach my $item (sort @array)
{print $prefix.$item."\n";}
}
my $root = "e:\\";
sub printArray;
opendir (DIR, $root);
my @contents = readdir (DIR);
printArray (\@contents);
I keep on getting an error on with, apparently, @array being unitialized. Upon further investigation it appears that the problem is in the assignment to @array.:eek: Apparently it doesn't like scalar symbol not directly being followed by another variable type character (ie. $ @ % & etc.) or a variable name.
I tried removing the brackets around $_[0], but then it seemd to be trying to perform the deferencing on just the $_; not including the [0]; I found a workaround by: :mad:
my $temp = $_[0];
my @array = @$temp;
but this is an ugly workaround, wastes memory (ie. extra variable), and its ugly/cumbesome/annoying/etc.. :rolleyes:It also seems very unPerl-ish. Is this a bug or is this intentional? If its intentional anyone care to explain WHY?!? Does anyone else have this problem or this just w/ my interpreter?:confused:
sub printArray {
my @array = @($_[0]);
my $prefix = (defined $_[1])? $_[1]: "";
foreach my $item (sort @array)
{print $prefix.$item."\n";}
}
my $root = "e:\\";
sub printArray;
opendir (DIR, $root);
my @contents = readdir (DIR);
printArray (\@contents);
I keep on getting an error on with, apparently, @array being unitialized. Upon further investigation it appears that the problem is in the assignment to @array.:eek: Apparently it doesn't like scalar symbol not directly being followed by another variable type character (ie. $ @ % & etc.) or a variable name.
I tried removing the brackets around $_[0], but then it seemd to be trying to perform the deferencing on just the $_; not including the [0]; I found a workaround by: :mad:
my $temp = $_[0];
my @array = @$temp;
but this is an ugly workaround, wastes memory (ie. extra variable), and its ugly/cumbesome/annoying/etc.. :rolleyes:It also seems very unPerl-ish. Is this a bug or is this intentional? If its intentional anyone care to explain WHY?!? Does anyone else have this problem or this just w/ my interpreter?:confused: