Here is my find example. I use this when I need to remember how to use find. Course I didn't know about File::Find::Rule! Good to know.

use strict; use File::Find; print "starting a find for all files:\n"; my $files = myfind('.'); printf "Found %d files.\n", scalar(@{$files}); print "starting a find for all files matching critera:\n"; $files = myfind('.', \&criteria); printf "Found %d files.\n", scalar(@{$files}); # critera function is called by find for each file. # passed the filename found, and must return boolean # indicating whether to include the file in the result # or not. sub criteria { my $filename = shift; return $filename =~ /example/i; } # find function that will return an array or array reference # containing the files that match the criteria. # accepts two parameters: # directory to search # optional criteria function. # sub myfind { my $dir = shift; my $criteriaFunc = shift || sub{1;}; my $list = []; find({wanted=>sub{findcb($list, $criteriaFunc)}}, $dir); return((wantarray)?(@$list):($list)); } # callback function called by find each time a file is found. # this callback will add the file to the listref if it matches # the critera. sub findcb { my $listref = shift; my $criteriaFunc = shift; if($criteriaFunc->($File::Find::name)) { push @$listref, $File::Find::name; } }

"Look, Shiny Things!" is not a better business strategy than compatibility and reuse.


In reply to Re: help needed with File::Find and arrays. by osunderdog
in thread help needed with File::Find and arrays. by basarix

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.