perlquestion
kevind0718
Hello Monks:<br><br>
I come to you because I know you are kind and wise. <br>
I have written a number of parsers for CSV files and they have all been straight forward. Just used Text::CSV_PP to parse the lines into an array and away you go. <br>
However the lastest CSV file I have been tasked with parsing has caused me much grief. There is something different about it. If I attempt to parse the file as I received it, the following code returns undefined: <br>
$status = $csv->parse($row);<br>
$col = $csv->fields();<br><br>
$col is undefined. CSV_PP seems to be getting confused. Which means this loop will also fail:<br>
while (defined($col = $csv->getline($fh) )) {<br><br>
If I open the same CSV file in MS-Excel and save it out under a different name, as a CSV file, the parsing works just fine. <br><br>
To get a handle on what is going on here I wrote this bit of code. <br><br>
<code>
while (defined($line = <> )) {
print $line . "~~\n";
for ( $i=0; $i <length($line); $i++) {
$char = substr($line, $i,1);
$hex = sprintf("%1x", $char);
print $char . "\t". $hex . "\n";
} #for
print "--new line--\n";
} #while
</code>
What I am trying to do is read the text file in and then print out the line. Then print each character, every character including non-printables, and the corresponding hex value. This line is failing:<br>
$hex = sprintf("%1x", $char);<br><br>
just want to get the hex value of the character. But my Perl is not strong enough.<br><br>
your kind assistance is requested.<br><br>
kd