# grab user input.. print "Enter the name of the file to read: "; my $filetoread = ; chomp($filetoread); print "Enter the name of the file to write: "; my $filetowrite = ; chomp($filetowrite); # ****print "Enter the name of the output file: "; # ****my $fileoutput = ; # ****chomp($fileoutput); # ****open $in, "new( { binary=>1 } ); open my $writehandle, '>', $filetowrite or die "Unable to write [$filetoread]!"; # ****open $out, ">output.csv" or die "output.csv: $!\n"; $csvo = Text::CSV->new( { binary=>1, eol=>$/ } ); $ar = $csvi->getline($filetoread); $col = 0; # ****$ar = $csvi->getline($in); $col = 0; foreach (@{$ar}) { $_ = "Col$col" if $col>7; s/ //; $col++; } $csvi->column_names($ar); $csvo->column_names(@hdr); $csvo->print($out,\@hdr); while ($hri = $csvi->getline_hr($in)) { if ($hri->{InvDate}) { ($dd,$mm,$yyyy) = split("/",$hri->{InvDate}); $hro = { DeviceID=>$hri->{CustCode}, PosTxnID=>$hri->{InvNum}, MobileNumber=>'', Timestamp=>$yyyy.'-'.$mm.'-'.$dd.' 00:00', PosID=>'', PosUserID=>'', ShopID=>'2345', Prodcode=>$code, ProdDescription=>$desc, ProdDept=>'', ProdGroup1=>'', ProdGroup2=>'', Qty=>$hri->{Qty}, Value=>$hri->{NetAmt} }; if ($spacer) { $csvo->print($out,\@e14); $spacer = 0; } $csvo->print_hr($out,$hro); } elsif ($hri->{CustCode}) { ($code,$desc) = split(' - # ',$hri->{CustCode}); } elsif ($hri->{LineDisc}) { $spacer = 0; } } # Original code had { $spacer = 1; } I changed this as my input.csv file originally had a - but then started arriving with - # between the Product code and product description in the input.csv file