Oh perl masters, please show me the way!!! Alright, my issue in a nut shell is... I have a folder packed full of csv files. In each csv file there are 2 fields (NAME, VALUE). I need to combine all these files into one file BUT here is where I am stuck.. each csv is named by a specific data/24time (ie 20080220013000.csv).
As i loop through these csv's I need to add the file name as a column, so I would end up with 3 fields in the combined new csv file (NAME,VALUE,DATETIME) this is so i can differentiate between the files when I go to do some final analysis.
Right now I am just trying to add the DATETIME to one csv (will work on looping through all the files after I get this working) here is what i've managed to come up with so far (ps it does't work either!)
-
#!/usr/local/bin/perl
-
#use strict;
-
use warnings;
-
use tie::File;
-
my $InDir="D:\\input";
-
my $OutDir="D:\\output";
-
my $file_count=0;
-
my $directory_count=0;
-
my $file_out="temp_out.csv";
-
-
opendir(DIR, $InDir);
-
LINE: while(my $FILE = readdir(DIR)) {
-
next LINE if($FILE =~ /^\.\.?/);
-
## check to see if it is a directory
-
if(-d "$FILE"){
-
$directory_count++;
-
}
-
else {
-
$file_count++;
-
}
-
}
-
closedir(DIR);
-
-
my @dirSen;
-
opendir(DIR, $InDir) or die "Unable to open dir $InDir: $!\n";
-
@dirSen = sort readdir(DIR);
-
my $dir_sen_contents = $dirSen[2];
-
close(DIR);
-
#$dir_sen_contents is now the first file of sensor directory
-
#print "$InDir\\$dir_sen_contents\n";
-
-
open (FILE, "$InDir\\$dir_sen_contents") || die "Cannot write to $dir_sen_contents\n";
-
open (TMP, ">$OutDir\\$file_out") || die "Cannot write to $file_out\n";
-
my @TMP=(<FILE>);
-
my $tmp2=@TMP;
-
for(my $i = 0; $i < $tmp2; $i +=1) {
-
$TMP[$i][3] = "$dir_sen_contents"}
-
print @TMP;
-
close FILE;
-
close TMP;
ps. i get an error Can't use string ("NAME,VALUE") as an array ref while "stricts ref" in use at line 37
Any assistance will be greatly appreciated.
Thanks ahead of time
Eric