Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Puzzled by File::Find

by dbae (Beadle)
on May 03, 2012 at 13:54 UTC ( #968741=perlquestion: print w/replies, xml ) Need Help??
dbae has asked for the wisdom of the Perl Monks concerning the following question:

Here is my code, in a file called ~/bin/t
#!/opt/local/bin/perl use strict; use diagnostics; use warnings; use File::Find; my $d = "/Users/dbae/tmp"; find(\&p,$d); sub p { };
Here are some hints from tcsh:
H2:~% pwd /Users/dbae H2:~% ls -ld . drwxr-xr-x+ 99 dbae dbae 3366 3 May 14:41 ./ H2:~% ls -ld tmp drwxr-xr-x 68 dbae dbae 2312 3 May 14:14 tmp/ H2:~% ~/bin/t # name of file containing perl code
Here is the output:
Can't cd to (/Users/dbae/tmp/) tmpvdlE9a: Permission denied at /Users/dbae/bin/t line 7 Can't cd to (/Users/dbae/tmp/) tmpZgzgiz: Permission denied at /Users/dbae/bin/t line 7
What am I doing wrong? Thanks. David

Replies are listed 'Best First'.
Re: Puzzled by File::Find
by Eliya (Vicar) on May 03, 2012 at 14:15 UTC

    Presumably, you don't have permission to access the directories

    /Users/dbae/tmp/tmpvdlE9a /Users/dbae/tmp/tmpZgzgiz

    You have shown what the permissions of tmp/ are, but not the permissons of those directories.

      Nail on the head. Thanks. I had stupidly assumed that these funny names were constructed by File::Find. Is there an easy way to tell File:Find to skip directories when not permitted to look at them?
        Use -d, -r, & -x functions to test the permissions to accept or reject a file.
        Sorry: a misleading request. Presumably File::Find::find will automatically skip unreadable directories, and output an error message to STDERR. So I don't need to tell find to do any skipping. I think I should keep quiet for a while!!
Re: Puzzled by File::Find
by stevieb (Monsignor) on May 03, 2012 at 14:15 UTC

    In ls man page states that the trailing '+' in the ls -ld output means there are extended permissions (Access Control Lists) on the /Users/dbae directory.

    Perhaps these ACLs are restricting the user running the script from changing into the tmp dir. I've never used ACLs on any 'nix before, so it may be worth looking into. It looks like you can use the -e option to ls to see access control list entries.

    Out of curiosity, can you actually cd into the tmp directory with the user your script is running as? This wasn't shown in your above output.

    Update: D'oh! Somehow I completely missed the fact that the OP was recursing one level further as Eliya pointed out, which probably makes this post irrelevant. That's what I get for coming into work too early before having enough coffee.

Re: Puzzled by File::Find
by Khen1950fx (Canon) on May 03, 2012 at 14:29 UTC
    To make it easier, use File::Find::Wanted. Here's a snippet that looks for all the files in /tmp:
    #!/usr/bin/perl -l use strict; use warnings; use File::Find::Wanted; my $d = '/tmp'; my @files = find_wanted(sub { -f && /\./ }, $d); foreach my $file(@files) { print $file; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://968741]
Front-paged by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2017-06-24 04:25 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (556 votes). Check out past polls.