Home  |  Linux  | Mysql  | PHP  | XML
From:Jay Savage Date:Mon Mar 22 17:25:30 2010
Subject:Re: 2 off in array count and index
On Tue, Mar 16, 2010 at 11:47 AM, jbl <jbl02g@gmail.com> 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

Navigate in group perl.beginners.cgi at sever nntp.perl.org
Previous Next


Your recent visits
Re: cgi and php database interaction
Re: cgi and perl database interaction
Re: problems with 'require'
Re:
ERROR: malformed header



  
© No Copyright
You are free to use Anything, but please consult your advocate before doing so as this website
also list content from other sources which may be copyrighted.
Site Maintained by Zareef Ahmed
Powered By PHP Consultants