select sub directories / File::Find?

G

Geoff Cox

Hello,

The following code will put the addresses from the multiple versions
of the nominal_3.htm files in a series of sub directories of
d:/addresses into a file called addresses-file ...

but I cannot see how to create a different file for each sub
directory...How do I select each different sub directory using
File::Find? Ideas please?! I

Thanks

Geoff


use warnings;
use strict;
use File::Find;

my $dir = 'd:/addresses';
find ( sub {
if ($_ =~ /nomination_3.htm/) {
print ("$_ \n");
open (IN, $_) or die ("Cannot open file $_ \n");
my $line = <IN>;
while (defined($line = <IN>)) {
if ($line =~ /<TD>(.*?)<\/TD>/i) {
open (OUT, ">>d:/addresses/addresses-file");
print OUT ("$1 \n");

}
}
}
}, $dir);
close (OUT);
close (IN);
 
T

Tad McClellan

Geoff Cox said:
How do I select each different sub directory using
File::Find? Ideas please?!


by examining the $File::Find::dir variable in the find subroutine,
or by using a relative rather than absolute filename in open().

open (OUT, ">>d:/addresses/addresses-file");


open (OUT, ">>addresses-file") or
die "could not open addresses file in the $File::Find::dir directory $!";
 
G

Geoff Cox

by examining the $File::Find::dir variable in the find subroutine,
or by using a relative rather than absolute filename in open().




open (OUT, ">>addresses-file") or
die "could not open addresses file in the $File::Find::dir directory $!";

Many thanks Tad

Geoff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top