Re: 2 off in array count and index
[email protected] (Jay Savage) Mon, 22 Mar 2010 13:25:30 -0400
| Newsgroups | perl.beginners.cgi |
|---|---|
| Message-ID | <[email protected]> |
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 =3D @files I get 1027 > With $last =3D $#files I get 1026 > $files [0] =3D . > $files[1] =3D .. > 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 =3D 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 =E2 will give rise to dom!