develooper Front page | perl.perl5.porters | Postings from May 2004

Re: FW: File::Find modified to pass arguments to the wanted function (with attachment)

Thread Previous | Thread Next
From:
Gisle Aas
Date:
May 20, 2004 04:03
Subject:
Re: FW: File::Find modified to pass arguments to the wanted function (with attachment)
Message ID:
lrn043icnb.fsf@caliper.activestate.com
"Roger Yager" <roger.yager@eyestreet.com> writes:

>             Over the years I have found myself using the File::Find module
> quite extensively.  However, there has been several times where I wanted to
> pass arguments to the callback routine instead of using global variables.  

Another option is simply to pass a closure that capture the arguments
you want your callback to receive.  So instead of:


  find({ wanted => \&foo,
         wanted_argref => $something,
       },
       @files);

do:

  find(sub { foo($something) },
       @files);

> Therefore, I have taken the initiative and updated the File::Find module to
> allow the passing of an optional hash reference to the callback routine.
> This was done by creating the new option "wanted_argref" which will hold a
> reference to the hash table that should be passed as an argument to the
> callback routine.  The module behaves the same with or without the
> modification yet allows for more flexibility in handling the data received
> by find.  

I consider using the closure good enough and that we don't need this.
If we still adopt this, then the new option should be renamed
'wanted_arg' as File::Find would not care if a reference or something
else is passed here.  Alternatively 'wanted_args' which would be an
array reference which is then passed as @_.  This allow more than one
arg to be passed.

But again, I think File::Find is fine as it is.

Regards,
Gisle

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About