You seem to have the fastest solution. Unless I miss my guess, File::Find is too much for an operation like this:

#!/usr/bin/perl -w use strict; use Benchmark; use File::Find; my @paths = (split/\:/,$ENV{PATH}); sub which1 { my $filename= "test.txt"; foreach my $pathname (@paths) { print "$pathname/$filename\n" if ( -e "$pathname/$file +name" ); }; } sub which2 { my $filename = "test.txt"; finddepth sub {print "$_\n" if ( /$filename$/)} , @paths; } timethese (100, {'whichone' => \&which1, 'whichtwo' => \&which2});

Yields:

[10:27:15 jhorner@gateway scripts]$ ./ch0as-1.pl test.txt Benchmark: timing 100 iterations of whichone, whichtwo... whichone: 0 wallclock secs ( 0.01 usr + 0.02 sys = 0.03 CPU) @ 33 +33.33/s (n=100) (warning: too few iterations for a reliable count) whichtwo: 14 wallclock secs (12.54 usr + 1.55 sys = 14.09 CPU) @ 7 +.10/s (n=100)

Unless someone can tell me why the File::Find version takes so long, I'm stumped. I have a feeling it has to do with File::Find traversing the entire filetree under the @path directories. If someone can let me know how to make it search ONLY the @path directories and not subdirectories, I'll be grateful.

I also have a feeling that File::Find is overkill in this, since you aren't recursing the directory structure.

Anyone else have good info on this?

J. J. Horner
Linux, Perl, Apache, Stronghold, Unix
jhorner@knoxlug.org http://www.knoxlug.org/

In reply to RE: Which by jjhorner
in thread Which by ChOas

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.