Bryan Keller wrote:
> Hi all,
>
> The following gets me the lines I need for any single txt file.
>
> #!usr/bin/perl
> use warnings;
> use strict;
>
> my @output = <>;
> print "$ARGV";
> print ("\nESTIMATION\n");
> print @output[18,21..24,28..31,206..208];
> print "\nPOPULATION\n";
> print @output[220,223..226,229..233,424..426];
>
> These txt files are in groups of 25 (in folders). My goal is to automate
> this so that after specifying a folder, Perl will pull the specified lines
> from each of the 25 txt files in that folder and write them to a single
> output file.
>
> I would greatly appreciate any help or suggestions!
Are you able to specify the files using wildcards on the commandline ?
If so, you could do it that way or you could select which ones you
want inside the script - eg (untested):
use strict;
use warnings;
my $dir = 'some path here'; # dir to peruse
my $ofile = 'some path here'; # output file
opendir DIR, $dir or die "opendir $dir: $! ($^E)";
my @files = readdir DIR;
closedir DIR;
open OUT, $file or die "create $ofile: $! ($^E)";
foreach my $file (@files) {
next if not /some reg exp criteria here/; # drop inappropriate files
open IN, $file or do {
warn "open $file: $! ($^E)"; # or die if you like
next;
};
my @content = <IN>; # slurp file
print "Doing $file\n"; # debug
# your orig code more or less
print OUT "ESTIMATION\n";
print OUT @content[18,21..24,28..31,206..208];
print OUT "\n";
print OUT "POPULATION\n";
print OUT @content[220,223..226,229..233,424..426];
print OUT "\n";
}
close OUT;
__END__
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs