Shobha Deepthi am Donnerstag, 7. Juli 2005 06.19:
> Hi,

Hi

probably not the best answer, but nobody else answered:

>  Am using find method in File::Find module.
>  Right now this method is being used as follows:
>        find({wanted => \&find_and_instantiate_commav_file,
>                   no_chdir => 0},
>                   $spec_entry);
>
> But I want to pass another parameter to find_and_instantiate_commav_file
> subroutine. I tried,
>      find({wanted => \&find_and_instantiate_commav_file("some_value"),

You can't pass an argument while defining a subroutine reference in general.

BTW, from the File::Find man page:

"The wanted function takes no arguments but rather does its work through a 
collection of variables."

>                   no_chdir => 0},
>                   $spec_entry);
>
> And the sub routine is as follows:
>
> sub find_and_instantiate_commav_file() {
>
>     my $slave_path = shift;

No argument passed to the sub, so @_ is empty, and that's the reason for the 
error message below.

> *LINENO:*      if ( /,v$/ )
>      {
>          // do something
>      }
> }
>
> This fails with,
> Use of uninitialized value in pattern match (m//) at ...*LINENO*
> Not a CODE reference at /usr/local/oracle/perl/5.8.1/lib/File/Find.pm
> line 792.
>
> Can anyone let me know how to pass parameters to subroutine refernced in
> find method and how to
> access these within the subroutine.


You can use a lexical my-variable, which you set before invoking find, and 
accessing from within the wanted sub.


hth, joe

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to