Hi,
I am new to perl. I need a code to read a csv file and replace the 5th field by a value.
E.g. in the csv file if the 5th field is 'C' , then replace it as 1 else replace with 2.
The output file must be a different file.
I have written a code for it. Can anyone tell me if its correct or not.
#!/usr/bin/perl -w
$arg1=$ARGV[0];
$arg2=$ARGV[1];
open INP,"<" ,$arg1;
open OUT,">" ,$arg2;
while($line=<inp>)
{
@arr=split(/,/,$line,5);
if (arr[4] eq 'C')
{
arr[4]=1;
}
else
{
arr[4]=2;
}
$str=join(',',@arr);
print OUT $str;
}
close INP;
close OUT;</inp>
Please help me someone.. Its very urgent.
If its not correct then please write an alternative code for it.
Thanks
Deepak