On Tue, Mar 16, 2010 at 11:47 AM, jbl <[email protected]> wrote:
> 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??
>
As others said, '.' is the link to the current directory and '..' is
the link to the parent directory.
Now, as for why they're showing up in your list...
> my @files = grep !/^\.png/, readdir FILENAMES;
This means "give me everything that doesn't start with '.png'." In
addition to '.', it will grab jpegs, tiffs, and anything else in the
directory that doesn't have a filename beginning with '.png'. You
probably want:
/\.png/ # everything that contains '.png', or
/\.png$/ # everything that ends with '.png'
HTH,
-- j
--------------------------------------------------
This email and attachment(s): [ ] blogable; [ x ] ask first; [ ]
private and confidential
daggerquill [at] gmail [dot] com
http://www.tuaw.com http://www.downloadsquad.com http://www.engatiki.org
values of β will give rise to dom!
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/