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

Hi everyone,

I'm stumped on this File::Find module, I'm getting an error and not sure why. I'm trying to run a find all files under a directory, this is just the first part of the script.

my (%master, %slave); my $confDir = "/opt/drutt/ca/conf"; print "Running local find for master \n"; find( sub { -f && $master{$_} = $File::Find::name }, $confDir);

The error is this:

Can't modify logical and (&&) in scalar assignment at AuditConf.pl lin +e 16, near "$File::Find::name }" Execution of AuditConf.pl aborted due to compilation errors.

Help.

Thanks,
Iconx

Replies are listed 'Best First'.
Re: File::Find Problem ( Can't modify logical and (&&) in scalar assignment )
by Anonymous Monk on Nov 07, 2016 at 22:09 UTC

    Its simple precedence issue, read perlop, && binds tighter than assignment, instead use  -f $_ and $master{$_} = $File::Find::name

Re: File::Find Problem
by Laurent_R (Canon) on Nov 07, 2016 at 23:30 UTC
Re: File::Find Problem
by tybalt89 (Monsignor) on Nov 08, 2016 at 08:20 UTC

    Alternate solution:

    find( sub { -f && ($master{$_} = $File::Find::name) }, $confDir);