Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > File::Find losing one file?

Reply
Thread Tools

File::Find losing one file?

 
 
seven.reeds
Guest
Posts: n/a
 
      06-21-2007
Hi,

I have a directory hierarcy that is holding some "news" articles [a
local term for some loosely related files]. The hierarchy is based on
the date of creation: ./YYYY/MM/DD/<article_number>.news

I am using File::Find to crawl through the dirs to find the ".news"
files. As it finds a news file it appends the full pathname to an
array. I know that there are X news files in the tree but (X-1) are
ever returned from File::Find.

Ideas are welcome, please

I am doing:

use File::Find;
my @articles = ();
find({wanted => \&findArticle, no_chdir => 1}, ".");
warn "#### $#articles\n";
....

sub findArticle()
{
if (-f && /\d+.news/)
{
push(@articles, $_);
}
}

 
Reply With Quote
 
 
 
 
seven.reeds
Guest
Posts: n/a
 
      06-21-2007
nevermind. It is my fault. There is not a problem

cheers

 
Reply With Quote
 
 
 
 
Brian Helterline
Guest
Posts: n/a
 
      06-21-2007
seven.reeds wrote:
> Hi,
>
> I have a directory hierarcy that is holding some "news" articles [a
> local term for some loosely related files]. The hierarchy is based on
> the date of creation: ./YYYY/MM/DD/<article_number>.news
>
> I am using File::Find to crawl through the dirs to find the ".news"
> files. As it finds a news file it appends the full pathname to an
> array. I know that there are X news files in the tree but (X-1) are
> ever returned from File::Find.
>
> Ideas are welcome, please
>
> I am doing:
>
> use File::Find;
> my @articles = ();
> find({wanted => \&findArticle, no_chdir => 1}, ".");
> warn "#### $#articles\n";


$#articles returns the last index of @articles which is X-1 elements
in the array since arrays start with index 0.

If you want the number of elements in @articles, evaluate the array in
scalar context;

my $nelements = @articles;
or
my $nelemenets = $#articles + 1;
 
Reply With Quote
 
Marc Espie
Guest
Posts: n/a
 
      06-23-2007
In article < .com>,
seven.reeds <> wrote:
>sub findArticle()
>{
> if (-f && /\d+.news/)
> {
> push(@articles, $_);
> }
>}


You know that your regexp is wrong, right ? It will catch up more
stuff than you want because:
- . stands for `any character', not just .
- you don't anchor it at all.

This expr will also catch stuff like
this42anewsletter
which might or might not be what you want...
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Regex losing <br> (different from the earlier topic about losing $1) Jason C Perl Misc 4 06-26-2012 10:29 PM
PIX losing responses from one particular DMZ website pfisterfarm Cisco 1 04-06-2010 04:46 AM
Losing Drives - Finding Drives - Losing Drives mel@no.spam.com Computer Support 2 09-21-2007 10:16 PM
Losing one row of datagrid when changing dropdownlist inside it. Luis Esteban Valencia ASP .Net 0 03-23-2005 05:04 PM
Losing round one to about:blank Ionizer Computer Support 5 03-17-2005 11:34 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57