
oldrob
Novice
Mar 13, 2013, 5:17 PM
Post #1 of 3
(164 views)
|
|
modifying a program to open all files in a directory
|
Can't Post
|
|
Hello Perl Gurus, I have written a script to take input files, copy specific data and output a combined file (see code below). Id like to make it so that I just have to specify a directory on the command line so that the script will automatically work on all the contained files - any help much appreciated!
#a program to parse flow data #!/usr/bin/perl use warnings; my @buffer; my @data; foreach (@ARGV) { $filename = $_; #sets the filename variable open (my $fh, '<',$filename); $lineno = 1; while (<$fh>) { $lineno++; if ($lineno == 3) { chomp(@buffer = <$fh>); #copy the entire line to @buffer unshift(@buffer, "$filename \t"); #add the filename before the string push (@buffer, "\n"); #add a newline after the string push (@data, @buffer); } } } open OUTPUT, '>', "output.txt"; print OUTPUT "@data";
|