in reply to Opening multiple files in directory
#!/usr/bin/perl use strict; my %count; my $directory = "c:\\Test"; opendir( DIR, $directory ) || die "Unable to open directory - $!\n"; my @files = grep /\.txt/, readdir( DIR ); closedir( DIR ); open( OUTFILE, ">> $directory\\COID_LIST.txt" ) || die "Unable to open write file! - $!\n"; foreach my $file (@files) { open( FH, "$directory\\$file" ) || die "Unable to open $file - $!\n"; while( <FH> ) { my $ID = substr( $_, 260, 5 ); print OUTFILE "$ID\n"; $count{$ID}++ if ( defined( $ID ) ); } close( FH ); } print "Number of company ID = " . scalar keys %count;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Opening multiple files in directory
by molson (Acolyte) on Mar 19, 2009 at 16:55 UTC | |
by kennethk (Abbot) on Mar 25, 2009 at 22:57 UTC |