I was fiddling around with
File::Find and
was finally able to get what I wanted using strict and
warnings but am not sure if my methods are sound. If there
are better ways to do the same thing, I'd like to learn.
I created a generalized sub in order to make repeated
searches with different arguments, as it doesn't make sense to
create separate wanted subs for each search.
The parts I'm particularly suspicious about are:
- the use of our (which gave warnings when I
used my)
- the use of the push function within sub
wanted.
- scoping of sub wanted within sub Search_File
Also, I would like to learn a little about the statement:
*name = *File::Find::name;
if someone could direct me what to look it up under. Thanks
for your time.
use strict;
my @found_files = Search_File('c:/Documents and Settings','udefdown.lo
+g');
foreach (@found_files) {
print "found: '$_'\n";
}
sub Search_File {
use File::Find ();
# for the convenience of &wanted calls, including -eval statements:
use vars qw/*name/;
*name = *File::Find::name;
our ($start_path, $search_name) = @_;
our @matching_files = ();
if ($search_name) {
# Traverse desired filesystems
File::Find::find({wanted => \&wanted}, $start_path);
}
return @matching_files;
sub wanted {
/^$search_name\z/si &&
push(@matching_files, $name);
}
}
"640K ought to be enough for anybody." -- Bill Gates, 1981
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.