using Find::file inside a sub-routine ..? 
Author Message
 using Find::file inside a sub-routine ..?

Hi, I am a newbie, and here's my question.
I found that File::find provides a great method of recursively
processing files in a directory. So I can have something like:
-----
use File::Find;
$dir1 = "/usr/local";
$dir2 = "/usr/bin";

sub process_files {
        # do some stuff in here

Quote:
}


-----

The nature of my project requires me to do all the above inside a particular
sub-routine. Is it possible?

sub Check {
        # do something
        # initialization, etc
        sub process_file {
                # do some other thing
        }

Quote:
}

Thanks,

-mel



Sun, 14 Oct 2001 03:00:00 GMT  
 using Find::file inside a sub-routine ..?
: Hi, I am a newbie, and here's my question.
: I found that File::find provides a great method of recursively
: processing files in a directory. So I can have something like:

[snip]

: The nature of my project requires me to do all the above inside a particular
: sub-routine. Is it possible?

Yes.

: sub Check {
:       # do something
:       # initialization, etc
:       sub process_file {
:               # do some other thing
:       }

: }

But not like that.  In Perl, you can't have one subroutine nested inside
another (well actually you can, but it doesn't behave the way you'd expect
it to).  Simply move the definition of process_file outside the definition
of Check.  If you want process_file and Check to be able to share
variables that should be invisible to the rest of your code, enclose both
of them in a block like so:

{my ($private_var_1, $private_var_2);

 sub process_file {
 ...
 }

 sub Check {
 ...
 }

Quote:
}



Sun, 14 Oct 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Error : calling sub routine inside another sub routine

2. oo programming and sub routines inside module

3. Problem in calling subroutine inside another routine

4. using sub routines from another file

5. Memory leak using anonymous subroutines inside an array

6. sub routine args, and using GD's newFromPng method

7. Unrecognized sub (Last subroutine in include file not found)

8. Passing file descriptor to sub inside a package?

9. Outer scope of a sub inside a sub

10. Closure in a subroutine inside a subroutine

11. Private subroutine inside subroutine

12. anonymous sub inside anonymous sub?

 

 
Powered by phpBB® Forum Software