in reply to File::Find problem
As I've just been ranting in another thread: callbacks aren't a great interface (to say the least).
I find File::Find so quirky to use that it usually takes me less time to write my own directory scanner than it does to figure out how to get File::Find to do what I want. Sure, for simple "do this to nearly every file" operations, File::Find can save me time. But for those I tend to use /bin/find instead anyway (from cygwin or find2perl if needed).
There are a few classic mistakes you need to keep in mind when searching a directory tree:
- tye#!/usr/bin/perl -w use strict; Scan( '/home/greg/mydir' ); sub Scan { my( $dir, $path )= @_; $path ||= "."; chdir $dir or die "Can't chdir($dir) from $path: $!\n"; $path= $dir if "." eq $path; my @files= ( glob("*"), grep "." ne $_ && ".." ne $_, glob(".*") ); for my $sub ( grep ! -l $_ && -d _, @files ) { Scan( $sub, "$path/$sub" ); } if( grep /\.old$/, @files ) { local( @ARGV )= "CPB"; local( $^I )= ".old"; while( <> ) { if( /^cat/ ) { print "cat\t/kat/src/all/b-ld_pipe.4go \\\n"; s/^cat\t/\t/; } print; } } chdir ".."; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: File::Find problem (yucky callbacks)
by zby (Vicar) on Mar 19, 2003 at 08:45 UTC | |
by tye (Sage) on Mar 19, 2003 at 09:29 UTC |