Closed p5pRT closed 19 years ago
# given a directory tree such as
$ mkdir -p f/g/h $ touch f/a f/g/b f/g/h/c
I want to get what find -depth reports $ find f -depth -type d -print f/g/h f/g f
#f2p is my wrapper around find2perl (see below) $ f2p f -depth -type d -print f
# Here's a one liner that also just prints11 $ perl -wl -MFile::Find -e 'File::Find::finddepth( sub { -d $_ && print $File::Find::name; }\, "f")' f
# I wanted all 3 directories to be printed
# instrumenting the wanted subroutine
perl -wl -MCwd -MFile::Find -e 'sub w{ print cwd\,"\t\$_=$_\t$File::Find::name" } File::Find::finddepth( \&w \, "f")'
#reports something like (if made the columns line up) # cwd $_ $File::Find::name /tmp/f $_=a f/a /tmp/f $_=. f /tmp/f/g $_=b f/g/b /tmp/f/g $_=g f/g /tmp/f/g/h $_=c f/g/h/c /tmp/f/g/h $_=h f/g/h
Notice wanted does get called with each of the desired directories but that 1) they still aren't in the right order\, and 2) when calling wanted for directory f/g and f/g/h we are not chdir'ed to the directory that would allow testing of -d $_ (we are still in the $_ directory)
####### here is f2p #!/usr/local/bin/perl
# f2p # dcd@tc.fluke.com # immediatly interpret the output find2perl
$FIND2PERL = '/usr/local/bin/find2perl';
pipe(READ\, WRITE); if (fork) { close(WRITE); $script = \<\<'DIE'; $SIG{__DIE__} = sub { print STDERR $_[0]; exit 1; }; DIE
while ($out = \
} else { close(READ); close(STDOUT); open(STDOUT\, ">&WRITE"); close(WRITE); $| = 1; do $FIND2PERL; close(STDOUT); }
I ran the one-liner you have above on Perl 5.8.5 on i686-linux\, and got...
steve@kirk find $ perl -wl -MFile::Find -e 'File::Find::finddepth(sub { -d $_ && print $File::Find::name; }\, "f")' f/g/h f/g f
It appears that this has been fixed somewhere along the line.
@smpeters - Status changed from 'open' to 'resolved'
Migrated from rt.perl.org#2218 (status was 'resolved')
Searchable as RT2218$