simonchristieis
Programmer
I'm new to Perl, just trying to create an xml file from a csv file:
The input file is of this format:
This is the error:
Can anyone point me in the right direction to resolve the error ?
Thanks in advance
Simon
Code:
{
my($fi) = $ARGV[0];
my($fo) = $ARGV[1];
my(@fields);
my(@fieldHeaders);
my($row);
my($i_count)=1;
my($ii_count)=0;
my($string);
sub trim($)
{
$string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
$string =~ s/\s+//g;
$string =~ s/\///g;
return $string;
}
open(FI,$fi) || die("Cannot open $fi as input.\n");
open(FO,">$fo") || die("Cannot open $fo as output.\n");
print FO "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<RESULT>\n";
while ($row=<FI>)
{
chop($row);
@fields = split(/,/,$row);
if($i_count==1)
{
@fieldHeaders = split(/,/,$row);
}
if($i_count!=1)
{
print FO "<item>\n";
foreach (@fieldHeaders)
{
print FO "<".trim($fieldHeaders[$ii_count]).">".trim($fields[$ii_count])."</".trim($fieldHeaders[$ii_count]).">\n";
$ii_count=$ii_count+1;
}
print FO "</item>\n";
}
$ii_count=0;
$i_count=$i_count+1;
}
print FO "</RESULT>\n";
close(FO);
close(FI);
}
The input file is of this format:
Code:
// field 1, field 2, field 3
value1, value2, value3
This is the error:
Code:
Use of uninitialized value in substitution (s///) at D:\quic_shares_cr_prod\Releases\Library\v3.1.20\MeanReversionToXML.pl line 15, <FI> line 873.
Use of uninitialized value in substitution (s///) at D:\quic_shares_cr_prod\Releases\Library\v3.1.20\MeanReversionToXML.pl line 16, <FI> line 873.
Use of uninitialized value in substitution (s///) at D:\quic_shares_cr_prod\Releases\Library\v3.1.20\MeanReversionToXML.pl line 17, <FI> line 873.
Use of uninitialized value in substitution (s///) at D:\quic_shares_cr_prod\Releases\Library\v3.1.20\MeanReversionToXML.pl line 18, <FI> line 873.
Use of uninitialized value in concatenation (.) or string at D:\quic_shares_cr_prod\Releases\Library\v3.1.20\MeanReversionToXML.pl line 43, <FI> line 873.
Use of uninitialized value in substitution (s///) at D:\quic_shares_cr_prod\Releases\Library\v3.1.20\MeanReversionToXML.pl line 15, <FI> line 873.
Use of uninitialized value in substitution (s///) at D:\quic_shares_cr_prod\Releases\Library\v3.1.20\MeanReversionToXML.pl line 16, <FI> line 873.
Use of uninitialized value in substitution (s///) at D:\quic_shares_cr_prod\Releases\Library\v3.1.20\MeanReversionToXML.pl line 17, <FI> line 873.
Use of uninitialized value in substitution (s///) at D:\quic_shares_cr_prod\Releases\Library\v3.1.20\MeanReversionToXML.pl line 18, <FI> line 873.
Use of uninitialized value in concatenation (.) or string at D:\quic_shares_cr_prod\Releases\Library\v3.1.20\MeanReversionToXML.pl line 43, <FI> line 873.
Use of uninitialized value in substitution (s///) at D:\quic_shares_cr_prod\Releases\Library\v3.1.20\MeanReversionToXML.pl line 15, <FI> line 873.
Use of uninitialized value in substitution (s///) at D:\quic_shares_cr_prod\Releases\Library\v3.1.20\MeanReversionToXML.pl line 16, <FI> line 873.
Use of uninitialized value in substitution (s///) at D:\quic_shares_cr_prod\Releases\Library\v3.1.20\MeanReversionToXML.pl line 17, <FI> line 873.
Use of uninitialized value in substitution (s///) at D:\quic_shares_cr_prod\Releases\Library\v3.1.20\MeanReversionToXML.pl line 18, <FI> line 873.
Use of uninitialized value in concatenation (.) or string at D:\quic_shares_cr_prod\Releases\Library\v3.1.20\MeanReversionToXML.pl line 43, <FI> line 873.
Use of uninitialized value in substitution (s///) at D:\quic_shares_cr_prod\Releases\Library\v3.1.20\MeanReversionToXML.pl line 15, <FI> line 873.
Use of uninitialized value in substitution (s///) at D:\quic_shares_cr_prod\Releases\Library\v3.1.20\MeanReversionToXML.pl line 16, <FI> line 873.
Use of uninitialized value in substitution (s///) at D:\quic_shares_cr_prod\Releases\Library\v3.1.20\MeanReversionToXML.pl line 17, <FI> line 873.
Use of uninitialized value in substitution (s///) at D:\quic_shares_cr_prod\Releases\Library\v3.1.20\MeanReversionToXML.pl line 18, <FI> line 873.
Use of uninitialized value in concatenation (.) or string at D:\quic_shares_cr_prod\Releases\Library\v3.1.20\MeanReversionToXML.pl line 43, <FI> line 873.
Can anyone point me in the right direction to resolve the error ?
Thanks in advance
Simon