Ben Crane wrote:
>
> I'm using file::find to (obviously!) find files, but I
> want the results to be placed in a text file so I can
> send the paths via email to others. Could someone have
> a look at this code (granted it might and is messy),
> But look at all lines beginning with * (near the
> bottom) and tell me why it dumps EVERY file it looks
> at into my text file. Any help would be appreciated.
> When i just print out the results to the screen, it
> works, when I try to put it into a file it doesn't...
>
>
> #!usr/bin/perl -w
use strict;
> use File::Find;
> use File::Basename;
You are not using (nor do you need to use) the File::Basename module
anywhere in this program.
> $match=<STDIN>;
> chomp($match);
> open(MYFILE, $match) || die "Can't open file: $!";
Instead of reading the file name from STDIN after the program runs why
not just type it on the command line after the program name (e.g.
yourprogram filename)
> open(DEST,">layerinfo.txt") || die "$!";
> while (defined($basename=<MYFILE>))
> {
> if ($basename){
> print "Searching for: $basename\n";
> chomp ($basename);
> find \&wanted, "q:/";
> }
> }
>
> sub wanted()
> {
>
> * %files = map {$_=>1} $basename;
> * if ($files=/$basename.TAB/i)
> * {print DEST "$File::Find::name\n" };
>
> }
> close (DEST);
> close ($match);
^^^^^^
close MYFILE;
It looks like you have a list of file names in a file that you want to
find.
#!/usr/bin/perl -w
use strict;
use File::Find;
my $match = shift or die "usage: $0 filename\n";
my %files;
{
local *TEMP;
open TEMP, $match or die "Can't open $match: $!";
chomp( my @temp = <TEMP> );
@files{ @temp } = ();
}
open DEST, '> layerinfo.txt' or die "Can't open 'layerinfo.txt': $!";
find( sub { exists $files{ $_ } and print DEST "$File::Find::name\n" },
'q:/' );
close DEST;
__END__
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]