This is my 2nd day as a Perl on Windows programmer (5.12 Strawberry) and i heard it many times to use strict and warnings, which seems like good advice. And use strict & use warnings has helped heaps.
But in one instance my code works only without use strict and i cannot find the reason for the error that i get in all my googling so far... Are there people with huge brains and eons of experience who can show me why this bit of code won't pass strict?
Error: Can't use string ("foo bar"...) as a symbol ref while "strict refs" in use
at M:\M\foobar+-.pl line 25.
But in one instance my code works only without use strict and i cannot find the reason for the error that i get in all my googling so far... Are there people with huge brains and eons of experience who can show me why this bit of code won't pass strict?
Code:
#!/usr/bin/perl use strict; use warnings; my $addone = 0; my $argnum = 0; my $numArgs = 0; my @FILE = (0..0); my @fileName = (0..0); my @fileSize = (0..0); ## With Perl, command-line arguments are stored in the array named @ARGV. $ARGV[0] contains the first argument, $ARGV[1] contains the second argument, etc. $#ARGV is the subscript of the last element of the @ARGV array, so the number of arguments on the command line is $#ARGV + 1. $numArgs = $#ARGV + 1; foreach $argnum (0 .. $#ARGV) { $addone = $argnum + 1; $fileName[$addone] = $ARGV[$argnum]; # Create File Handle. $FILE[$addone] = $fileName[$addone]; # Check the file is a normal file and exists. die "$FILE[$addone] does not exist\n" if not -f $FILE[$addone]; # Open file. open $FILE[$addone], "<", $fileName[$addone] or die "$FILE[$addone] cannot be opened!"; binmode ($FILE[$addone]); # Get file sizes. $fileSize[$addone] = -s $fileName[$addone]; print ("File $argnum \(Size:$fileSize[$addone]\):$fileName[$addone]\n"); }
at M:\M\foobar+-.pl line 25.
Comment