Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Passing arguments to File::Find

by Stegalex (Chaplain)
on Apr 10, 2002 at 18:07 UTC ( [id://158096]=perlquestion: print w/replies, xml ) Need Help??

Stegalex has asked for the wisdom of the Perl Monks concerning the following question:

I would like to pass an additional argument to File::Find's "find" sub but I am unable to do this because all args after $_[0] are presumed to be filenames. Am I SOL here or can you recommend an alternative approach? I like chicken.

Replies are listed 'Best First'.
Re: File::Find
by jplindstrom (Monsignor) on Apr 10, 2002 at 18:17 UTC
    From the POD:

    use File::Find;
    find({ wanted => \&process, follow => 1 }, '.');
    

    Note the { }.

    /J

      Thanks for the solution. I am sorry for overlooking this. I added another element to the hash named "foo" and then dereferenced it in &process() by saying:
      ${$_[0]}{foo}
      I like chicken.
Re: File::Find
by mirod (Canon) on Apr 10, 2002 at 19:11 UTC
Re: File::Find
by RMGir (Prior) on Apr 10, 2002 at 18:22 UTC
    I'm not too clear on what you mean...

    If something takes a code ref as an argument, you can always pass more arguments in to the code ref by making a closure.

    use strict; use File::Find; # make a closure that invokes &$arg2 on any filename that # ends in $arg1 sub makeExtClosure { my ($ext, $action) = @_; return sub { /$ext$/ && &$action; }; } find(makeExtClosure("pod", sub{print "$_\n"}), ".");
    Is that what you had in mind?
    --
    Mike

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://158096]
Approved by Stegalex
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2025-06-16 13:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.