brad211987
10-23-2006, 11:38 PM
I am new to perl, and am writing a script that takes a directory as an argument and prints the files in that directory and their corresponding file size. My problem is, the output is behaving randomly, at least it seems. when ran with the argument as the directory that the script is located in, it works, but if I give it another directory, it doesnt work for most files, it will work for the current and parent directory, and it will work for .pl files sometimes.
Here is the script:
#!/usr/bin/perl
use warnings;
$dir = shift @ARGV;
opendir MYDIR, $dir;
@files = readdir MYDIR;
closedir MYDIR;
foreach $listitem ( @files )
{
$filesize = -s $listitem;
print $filesize if defined $filesize;
print $listitem,"\n";
}
Does anyone see any problems in this? I am still working on it but am feeling a little lost at the moment.
Here is the script:
#!/usr/bin/perl
use warnings;
$dir = shift @ARGV;
opendir MYDIR, $dir;
@files = readdir MYDIR;
closedir MYDIR;
foreach $listitem ( @files )
{
$filesize = -s $listitem;
print $filesize if defined $filesize;
print $listitem,"\n";
}
Does anyone see any problems in this? I am still working on it but am feeling a little lost at the moment.