Hello Monks:
I come to you because I know you are kind and wise.
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.
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:
$status = $csv->parse($row);
$col = $csv->fields();
$col is undefined. CSV_PP seems to be getting confused. Which means this loop will also fail:
while (defined($col = $csv->getline($fh) )) {
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.
To get a handle on what is going on here I wrote this bit of 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
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:
$hex = sprintf("%1x", $char);
just want to get the hex value of the character. But my Perl is not strong enough.
your kind assistance is requested.
kd
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.