Hi Bryan, On Mar 4, 2009, at 1:27 AM, Bryan Keller wrote: > 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. The quick-and-dirty way of doing that would be to use the glob operator (documented at http://perldoc.perl.org/functions/glob.html). It's how you ask Perl to expand wildcards - so in Windows/DOS terms, it's like doing "dir *.*", except in Perl :-). You can read more about glob expansions at http://en.wikipedia.org/wiki/Glob_(programming).
You'll also need to modify your program to read from files, using open (there's a nice tutorial at http://perldoc.perl.org/perlopentut.html). If I were modifying your program, here's how I'd do it: --program.pl begins #!/usr/bin/perl use warnings; use strict; my @files_to_process = glob("FolderName/*.txt"); # Or "*.txt" if you want to process all the text files in the current folder # @files_to_process is now an array containing a list of # all files which match the pattern you specified - all # files with a "txt" extension in the folder "FolderName", # in my example above. foreach my $filename (@files_to_process) { open(INPUT, '<', $filename) or die "Could not open $filename: $!"; my @output = <INPUT>; print "$filename"; print "\nESTIMATION\n"; print @output[18,21..24,28..31,206..208]; print "\nPOPULATION\n"; print @output[220,223..226,229..233,424..426]; close(INPUT); } --program.pl ends Standard disclaimers about programs thrown together at 2am apply, but this program *seems* to run on my computer without any problems. I'm sure there are more efficient ways of reading particular lines out of a file, but I don't know any. I'm sure someone who does will post it shortly :-), and reading the whole file into memory like you're doing should work fine on small numbers of small files. You could also ask this question at the Perl Beginners mailing list (at http://learn.perl.org/faq/beginners.html) , who I imagine would know plenty o beginner-targeted resources to get you started on this sort of file manipulation. Hope that helps! cheers, Gaurav _______________________________________________ ActivePerl mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
