in reply to Fiddling with File::Find

You really want an anon subroutine, not a nested named subroutine (which isn't even permitted really anyway).
sub Search_File { require File::Find; my ($start_path, $search_name) = @_; my @matching_files = (); if ($search_name) { # Traverse desired filesystems File::Find::find(sub { /^$search_name\z/si && push(@matching_files, $name); }, $start_path); } return @matching_files; }
And now it's even backward compatible to the version of Perl my ISP is running (5.5.3).

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
Re: Re: Fiddling with File::Find
by jlongino (Parson) on Oct 06, 2001 at 02:18 UTC
    If I paste your snippet into a sample program strict complains about $name not being defined. If I include the two statements:
    use vars qw/*name/; *name = *File::Find::name;
    it works, but I get a warning message: Name "File::Find::name" used only once: possible typo at search.pl line 12 What is the proper way to define $name when using strict and warnings so that no messages are generated?

    "Whether you think that you can, or that you can't, you are usually right." -- Henry Ford

      Use those lines *before* you use warnings. It's a rather spurious warning, but hard to smack down in the source code.
        I appreciate your taking the time to hunt this down. Particulary since it is a relatively stale post. Maybe I should whine more often. (:

        This does work as you suggested if I use:  use warnings; but it doesn't seem to help if I use  perl -w. I seem to recall reading a post sometime back describing the differences between the two, so I'll look for it again. Maybe I don't really need to use "-w".

        Thanks again for your diligence!

        --Jim

      Sorry. I snipped your snippet in haste. Change $name to $File::Find::name. As for the warning, this is one of those times when the warning is a warning, but not really doing anything wrong. That's why I don't code "warning-free" occasionally.

      -- Randal L. Schwartz, Perl hacker