I can't tell by the code you've given above but I suspect when you're looking for a single file, you're calling it in scalar context which according to the docs will return the count of the files found rather than the list of files found.
Here's an example of how you might use it:
sub FindFile
{
my $file = shift;
my @directories = @_;
my $pathtofile;
unshift(@directories,"./");
# this could still cause scalar context...
# return File::Finder->name($file)->in(@directories);
# this forces list context
return @{[File::Finder->name($file)->in(@directories)]};
};
Disclaimer: I've never used this module before 5 minutes ago
Updated: returned the value from the File::Finder call directly rather than storing it in an array. I had first intended to only return the first element since the OP was only expecting one response and the name of the sub is
FindFile not
FindFiles but it's probably better to let the caller deal with multiple results rather than assume they only want one... (Thanks for the compliment merlyn :-)
Updated (again): well tye pointed out the problem with my fix (as suggested by merlyn) so I've fixed it again...
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.