Hi, everyone!!
i am new to perl programming.. plz help me.
#!C:/perl/bin
use warnings;
use strict;
use Text::CSV_XS;
my @rows = "";
my $row;
my $count;
my $fh;
my @fields = "";
my $csv = Text::CSV_XS->new ({binary =>1}) or
die "cannot use CSV:" .Text::CSV->error_diag ();
open $fh,"<:encoding(utf8)","week.csv" or die "week.csv";
while($row = $csv->getline($fh))
{
if($row->[20] == "null"){
for ($count=1; $count<=13; $count++)
{
$row->[$count] = "null";
}
}
push @rows,$row;
}
$csv->eof or $csv->error_diag ();
close $fh;
$csv->eol("\r\n");
open $fh,">:encoding(utf8)", "week.csv" or die "new.csv: $!";
$csv->print ($fh,$_) for @$row;
close $fh or die "new.csv:$!";
is this above program correct?
i get a error message saying:
'==' is use to compare numerice values only. If you want to compare other than numerice, you will use the 'eq' operator. So you aviod this error you modify the below lines in your code.
if($row->[20] eq ''){
For the previous lines you dump all the records at '@rows'. But here you are using the @$row. Change the line as below
$csv->print ($fh,$_) for @rows;
You are using the same file (week.csv) input as well as output file. give another name to the output file and Change the above lines and run the program. I hope you may be got the answer.