Question on File::Find

D

Diana

Hi,
I am struggling to use File::Find module,
the issue is, I can use with defining find function with &wanted, but
not with %options, here is what I am doing
my %findoption=( bydepth=>"1" , no_chdir => "1" );
push (@All,find(\%fort,"$Location"));
thx
-D
 
P

Paul Lalli

Diana said:
Hi,
I am struggling to use File::Find module,
the issue is, I can use with defining find function with &wanted, but
not with %options, here is what I am doing
my %findoption=( bydepth=>"1" , no_chdir => "1" );
push (@All,find(\%fort,"$Location"));

1) You didn't include the wanted option in your %findoption hash. If
you pass a hash reference as the first option to find, one of the
key-value pairs of that hash must be 'wanted' with the value of the
subroutine you want to call.
2) find() does not return a list of files it finds. I have no idea
what you think your push statement is doing
3) Do not needlessly double-quote variables (like you did to
$Location). See `perldoc -q quoting`

Paul Lalli
 
P

Paul Lalli

Paul said:
Diana wrote:

1) You didn't include the wanted option in your %findoption hash. If
you pass a hash reference as the first option to find, one of the
key-value pairs of that hash must be 'wanted' with the value of the
subroutine you want to call.
2) find() does not return a list of files it finds. I have no idea
what you think your push statement is doing
3) Do not needlessly double-quote variables (like you did to
$Location). See `perldoc -q quoting`

4) What the heck is %fort? You declared %findoption, but are passing a
reference to %fort? If this is your real code, please enable `use
strict;` and `use warnings;` in your code. If this is not your real
code, please DON'T DO THAT!

Paul Lalli
 
D

Diana

Paul said:
4) What the heck is %fort? You declared %findoption, but are passing
a reference to %fort? If this is your real code, please enable `use
strict;` and `use warnings;` in your code. If this is not your real
code, please DON'T DO THAT!

Paul Lalli

sorry for the mistake, I presume I modified during posting, my mistake,
it seems I am NOW able to use options like this


my %fort=(wanted=>sub{push (@AllDir,$File::Find::name)},bydepth=>"1" ,
no_chdir => "1" ); ;
find(\%fort,$Location);

--
 
B

Ben Morrow

Quoth "Diana said:
[File::Find]
it seems I am NOW able to use options like this

my %fort=(wanted=>sub{push (@AllDir,$File::Find::name)},bydepth=>"1" ,
no_chdir => "1" ); ;
find(\%fort,$Location);

There's no need to quote "1", either. Note that you can build the
hashref inline:

find ({
wanted => sub {
push (@AllDir, $File::Find::name);
},
bydepth => 1,
no_chdir => 1,
}, $Location);

Personally I wouldn't use any of those parens, but you may find them
helpful.

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top