I am reading a directory and creating an array of .png file names. I
know for a fact that there are 1025 png files in the folder
With $count = @files I get 1027
With $last = $#files I get 1026
$files [0] = .
$files[1] = ..
I have heard of being one off by not taking into account the
difference in number of elements and the index of the last element but
why am I 2 off?? As far as the dots in elements 0 & 1, I am sure that
that is something to do with the path, but what??

#!/usr/bin/perl -w
use strict;

opendir(FILENAMES, 'F:/_D_drive_IDE/TIGER2009_working_folder/
perl_scripts_copy')
                ||die "Cannot open directory $1";
my @files = grep !/^\.png/, readdir FILENAMES;
closedir FILENAMES;

$last = $#files;
$count = @files;

print 'Number of elements =>',$count,"\n";
print 'Index of last element =>',$last,"\n";

print 'array @files index[0] =>'.$files[0],"<=\n";
print 'array @files index[1] =>'.$files[1],"<=\n";
print 'array @files index[2] =>'.$files[2],"<=\n\n";
print $files[$lastIndex];
                                                       # actual files
= 1025
#the output is:
#Number of elements =>1027
#Index of last element =>1026
#array @files index[0] =>.<=
#array @files index[1] =>..<=
#array @files index[2] =>31052_50068.png<=      This is the first
actual file name


-- 
To unsubscribe, e-mail: beginners-cgi-unsubscr...@perl.org
For additional commands, e-mail: beginners-cgi-h...@perl.org
http://learn.perl.org/


Reply via email to