rongoral has asked for the wisdom of the Perl Monks concerning the following question:
I am having some difficulty with a module that is using File::Find. The method is below.
The idea is to feed FindPath a file name and directory so that all occasions of $file_name are pushed into @a_files. This works fine until I need to use FindPath again during the same session. What I'm finding is that even though @a_files looses scope within FindPath itself, it does not in ProcessFile. In other words, if FindPath returns and it is called a second time within the same session, @a_files is an uninitiated array in FindPath. However when ProcessFile is called, @a_files has retained the values it had from the last call to FindPath.
Am I making sense? Well here is what it looks like having been stripped down to the bare essentials.
From a .cgi file -
In FileMan.pmuse FileMan; use Cwd; my $fileman = new FileMan; my $first_path = $fileman->FindPath('file1.txt', cwd); my $second_path = $fileman->FindPath('file2.txt', cwd);
sub FindPath { #- Var Declaration And Initialization my ($hr_self, $file_name, $file_path) = @_; # Array to fill with file paths my @a_files = (); # Search file_path for the file find(\&ProcessFile, $file_path); #- The Subroutine To Process Files And Directories sub ProcessFile {if ($_ eq $file_name){push (@a_files, $File::Find::name);}} # Return the paths found return @a_files; } # end FindPath
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Confused scoping while using File::Find
by pg (Canon) on Oct 11, 2004 at 05:21 UTC | |
by rongoral (Beadle) on Oct 11, 2004 at 15:31 UTC | |
|
Re: Confused scoping while using File::Find
by ysth (Canon) on Oct 11, 2004 at 05:38 UTC | |
by rongoral (Beadle) on Oct 11, 2004 at 15:08 UTC | |
by pg (Canon) on Oct 11, 2004 at 17:56 UTC | |
by rongoral (Beadle) on Oct 12, 2004 at 13:02 UTC | |
|
Re: Confused scoping while using File::Find
by Zaxo (Archbishop) on Oct 11, 2004 at 05:30 UTC | |
by rongoral (Beadle) on Oct 11, 2004 at 15:39 UTC |