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:
hv
Date:
May 20, 2004 05:01
Subject:
Re: FW: File::Find modified to pass arguments to the wanted function (with attachment)
Message ID:
200405201203.i4KC3Ic15570@zen.crypt.org
Gisle Aas <gisle@ActiveState.com> wrote:
:"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);
[...]
:But again, I think File::Find is fine as it is.

I agree, but I notice quite frequently that people fail to spot that
they can do this; perhaps it would be worth adding something to the
File::Find docs that shows a simple example.

Hugo

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