File::Find losing one file?

Discussion in 'Perl Misc' started by seven.reeds, Jun 21, 2007.

  1. seven.reeds

    seven.reeds Guest

    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, $_);
    }
    }
    seven.reeds, Jun 21, 2007
    #1
    1. Advertising

  2. seven.reeds

    seven.reeds Guest

    nevermind. It is my fault. There is not a problem

    cheers
    seven.reeds, Jun 21, 2007
    #2
    1. Advertising

  3. 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;
    Brian Helterline, Jun 21, 2007
    #3
  4. seven.reeds

    Marc Espie Guest

    In article <>,
    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...
    Marc Espie, Jun 23, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Luis Esteban Valencia
    Replies:
    0
    Views:
    540
    Luis Esteban Valencia
    Mar 23, 2005
  2. Luis Esteban Valencia

    Losing one row of datagrid when changing dropdownlist inside it.

    Luis Esteban Valencia, Mar 23, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    145
    Luis Esteban Valencia
    Mar 23, 2005
  3. Wybo Dekker
    Replies:
    1
    Views:
    352
    Yukihiro Matsumoto
    Nov 15, 2005
  4. vdvorkin
    Replies:
    0
    Views:
    399
    vdvorkin
    Feb 10, 2011
  5. Jason C
    Replies:
    4
    Views:
    681
    Morty Abzug
    Jun 26, 2012
Loading...

Share This Page