Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: Traverse a directory

by asqwerty (Acolyte)
on Sep 05, 2012 at 11:47 UTC ( #991818=note: print w/replies, xml ) Need Help??

in reply to Traverse a directory

This works for me (using find in linux):

#!/usr/bin/perl use strict; use warnings; my $dirname = "your_directory"; my $user = "your_user"; my @fn = map {split /\n/} `find $dirname -user $user`; foreach my $f (@fn){ print "$f\n"; }

Replies are listed 'Best First'.
Re^2: Traverse a directory
by Anonymous Monk on Sep 05, 2012 at 14:34 UTC

    Apart from forking to an external process being of questionable use, your code will fail if $dirname contains a space, or a file name contains a line break; also, you cannot iterate over the list until you get it in full (could take a few minutes).

    Anyway, I'm saying that using modules is usually more robust and flexible and portable than shelling out to some command.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://991818]
[Eily]: for being inefficient?
[erix]: when the google-per-line coefficient > 1 you have located a good place to learn a lot ;)
[erix]: also known, I think, as a gravy train :P
erix google "gravy train" :)

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2018-05-22 15:48 GMT
Find Nodes?
    Voting Booth?