Hey all, Im back and in need of some help again. Once again I have been tasked with fixing a problem in someone else script and am completely stuck. The process of the script works just fine (basically filling gaps in one csv file $ARGV[0] based on another $ARGV[2]) but in the output .csv the header is not there and there is an extra space added...
[CODE=perl]
#!/usr/bin/perl
use File::Basename;
#use strict;
my $fileInput = $ARGV[0];
my $fileOutput = $ARGV[1];
my $fileTTable = $ARGV[2];
my $fileO = $ARGV[0];
my ( $filename, $finBase, $finDir ) = fileparse($file Output);
my $fileOut = $finDir . $finBase . $filename;
open( READER, $fileO ) or die "Can't open $file0: $!";
open( TT, $fileTTable ) or die "Can't open $file0: $!";
open( READ, $fileInput ) or die "Can't open $file0: $!";
open( WRITE, ">$fileOut" ) or die "Can't open $file0: $!";
my $maxDiff = 10;
my %tmcHash = {};
print WRITE "$category\ n";
while (<READ>) {
@line = split( /,/, $line1 );
$line1 = $_;
chomp($line1);
}
$hashValue = $line1;
close(READ);
$length = @line;
my %ttHash = {};
$header = $line[0];
$tmcHash{"$head er"} = $hashValue;
while (<TT>) {
$ttLine = $_;
chomp($ttLine);
}
@parts = split( /,/, $ttLine );
close(TT);
$key = $parts[0];
$value = $parts[1] . "," . $parts[2];
while (<READER>) $ttHash{"$key"} = $value;
{
$lin = $_;
chomp($lin);
@kkk = split( /,/, $lin );
$k = $kkk[0];
$temp1 = $tmcHash{"$k"};
@tarTmc = split( /,/, $temp1 );
@tarTmc2 = split( /,/, $temp1 );
$temp2 = $ttHash{"$tarTm c[0]"};
@adj = split( /,/, $temp2 );
$spike = 0;
my @preTmc = ();
my @nextTmc = ();
if ( $tmcHash{"$adj[0]"} ne "" ) {
$temp3 = $tmcHash{"$adj[0]"};
@preTmc = split( /,/, $temp3 );
}
if ( $tmcHash{"$adj[1]"} ne "" ) {
$temp4 = $tmcHash{"$adj[1]"};
@nextTmc = split( /,/, $temp4 );
}
$length = @tarTmc;
for ( $j = 1 ; $j < $length - 1 ; $j++ ) {
$count = 0;
my @vs = ();
if ( $tarTmc[$j] == -1 ) {
$total = 0;
if ( $tmcHash{"$adj[0]"} ne "" ) {
if ( $preTmc[$j] != -1 ) {
push( @vs, $preTmc[$j] );
$count++;
}
}
if ( $tmcHash{"$adj[1]"} ne "" ) {
if ( $nextTmc[$j] != -1 ) {
push( @vs, $nextTmc[$j] );
$count++;
}
}
$size = @vs;
for ( $i = 0 ; $i < $size ; $i++ ) {
$total += $vs[$i];
}
if ( $count != 0 ) {
$tarTmc2[$j] = $total / $count;
$tarTmc2[$j] = 10 * $tarTmc2[$j];
$tarTmc2[$j] = round( $tarTmc2[$j] );
$tarTmc2[$j] = $tarTmc2[$j] / 10;
}
}
}
print WRITE "$tarTmc[0]";
}
for ( $k = 1 ; $k < $length ; $k++ ) {
print WRITE ",$tarTmc2[$k]";
close(READER);
}
close(WRITE);
print WRITE "\n";
sub round {
my ($number) = shift;
return int($number);
}
[/CODE]
I know too the use strict is commented out and thats a bad bad thing..
I am assuming the issue has to do with $tarTMC[0] on line 128, but that is an assumption.. Anyways, I would greatly appreciate any thoughts on where i should look/research to help solve this problem
Thanks ahead of time.
Eric
[CODE=perl]
#!/usr/bin/perl
use File::Basename;
#use strict;
my $fileInput = $ARGV[0];
my $fileOutput = $ARGV[1];
my $fileTTable = $ARGV[2];
my $fileO = $ARGV[0];
my ( $filename, $finBase, $finDir ) = fileparse($file Output);
my $fileOut = $finDir . $finBase . $filename;
open( READER, $fileO ) or die "Can't open $file0: $!";
open( TT, $fileTTable ) or die "Can't open $file0: $!";
open( READ, $fileInput ) or die "Can't open $file0: $!";
open( WRITE, ">$fileOut" ) or die "Can't open $file0: $!";
my $maxDiff = 10;
my %tmcHash = {};
print WRITE "$category\ n";
while (<READ>) {
@line = split( /,/, $line1 );
$line1 = $_;
chomp($line1);
}
$hashValue = $line1;
close(READ);
$length = @line;
my %ttHash = {};
$header = $line[0];
$tmcHash{"$head er"} = $hashValue;
while (<TT>) {
$ttLine = $_;
chomp($ttLine);
}
@parts = split( /,/, $ttLine );
close(TT);
$key = $parts[0];
$value = $parts[1] . "," . $parts[2];
while (<READER>) $ttHash{"$key"} = $value;
{
$lin = $_;
chomp($lin);
@kkk = split( /,/, $lin );
$k = $kkk[0];
$temp1 = $tmcHash{"$k"};
@tarTmc = split( /,/, $temp1 );
@tarTmc2 = split( /,/, $temp1 );
$temp2 = $ttHash{"$tarTm c[0]"};
@adj = split( /,/, $temp2 );
$spike = 0;
my @preTmc = ();
my @nextTmc = ();
if ( $tmcHash{"$adj[0]"} ne "" ) {
$temp3 = $tmcHash{"$adj[0]"};
@preTmc = split( /,/, $temp3 );
}
if ( $tmcHash{"$adj[1]"} ne "" ) {
$temp4 = $tmcHash{"$adj[1]"};
@nextTmc = split( /,/, $temp4 );
}
$length = @tarTmc;
for ( $j = 1 ; $j < $length - 1 ; $j++ ) {
$count = 0;
my @vs = ();
if ( $tarTmc[$j] == -1 ) {
$total = 0;
if ( $tmcHash{"$adj[0]"} ne "" ) {
if ( $preTmc[$j] != -1 ) {
push( @vs, $preTmc[$j] );
$count++;
}
}
if ( $tmcHash{"$adj[1]"} ne "" ) {
if ( $nextTmc[$j] != -1 ) {
push( @vs, $nextTmc[$j] );
$count++;
}
}
$size = @vs;
for ( $i = 0 ; $i < $size ; $i++ ) {
$total += $vs[$i];
}
if ( $count != 0 ) {
$tarTmc2[$j] = $total / $count;
$tarTmc2[$j] = 10 * $tarTmc2[$j];
$tarTmc2[$j] = round( $tarTmc2[$j] );
$tarTmc2[$j] = $tarTmc2[$j] / 10;
}
}
}
print WRITE "$tarTmc[0]";
}
for ( $k = 1 ; $k < $length ; $k++ ) {
print WRITE ",$tarTmc2[$k]";
close(READER);
}
close(WRITE);
print WRITE "\n";
sub round {
my ($number) = shift;
return int($number);
}
[/CODE]
I know too the use strict is commented out and thats a bad bad thing..
I am assuming the issue has to do with $tarTMC[0] on line 128, but that is an assumption.. Anyways, I would greatly appreciate any thoughts on where i should look/research to help solve this problem
Thanks ahead of time.
Eric
Comment