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:
Roger Yager
Date:
May 20, 2004 10:20
Subject:
RE: FW: File::Find modified to pass arguments to the wanted function (with attachment)
Message ID:
auto-000000152587@eyestreet.com
Hugo,

	Thanks for the feedback.  I can't believe I overlooked the use of a
sub!  There was obviously no need to make the change to the module so I've
discarded my copy and gone back to using the module in its original form.  

	I like your idea of adding a simple example to the wanted section of
the documentation.  It might detour others from making the same mistake I
did.

Respectfully,
Roger Yager

-----Original Message-----
From: hv@crypt.org [mailto:hv@crypt.org] 
Sent: Thursday, May 20, 2004 8:03 AM
To: Gisle Aas
Cc: roger.yager@eyestreet.com; perl5-porters@perl.org
Subject: Re: FW: File::Find modified to pass arguments to the wanted
function (with attachment) 

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