good to see you got something that works. but you're mixing your methods in this example. you're getting the return value you want in
$fullpath, but you're not using the
File::Find module to do it. instead, you're using the backquotes, which executes an external program and returns the output as a single string containing all lines.
so, you've gone to the trouble of loading all these lines of code, only to ignore them. perhaps you should remove the use line, it's unneccessary in your example.
as an alternative, for an example of a 100% Pure Perl solution, try:
#!/usr/bin/perl
use strict;
use warnings;
use File::Find;
# the dir you're 'find'ing from
my $dir = shift || '.';
# the file you're looking for
my $file = 'blah';
# the results you want
my @results;
# the function you perform on each find value
sub looking_for_file
{
# push full filename to an array if file and name is $file
push(@results, $File::Find::name) if(-f $_ && $_ eq $file);
};
# the result you want, using File::Find::find()
# (not the external 'find' program)
find \&looking_for_file, $dir;
# print your results
print("my results are: @results\n");
In this example, you get an array (
@array) with the values of each file found named 'blah'. unlike also, this should run on just about any platform.
I know my example was a bit lengthy, so here's a shorter version:
#!/usr/bin/perl
use strict;
use warnings;
use File::Find;
# the shorter version
my @results;
find sub{-f $_ && $_ eq 'blah' &&
push(@results,$File::Find::name)}, shift || '.';
print("my results are: @results\n");
~Particle
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.