I'm not sure if this is a bug or my misunderstanding of the Perl syntax. I'm having problems with using references.
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.Code: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);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:
but this is an ugly workaround, wastes memory (ie. extra variable), and its ugly/cumbesome/annoying/etc..Code:my $temp = $_[0]; my @array = @$temp;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?
![]()





Apparently it doesn't like scalar symbol not directly being followed by another variable type character (ie. $ @ % & etc.) or a variable name.
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?

Reply With Quote