I am going to make a bet that this particular record that is
causing you problems contains 22 commas, but not 22 fields.
I will also guess, without seeing your data set, that one of your
fields is a freeform text entry field, followed by some
numeric fields.
Somebody put commas in the freeform field and split() is doing
exactly what you asked. Only now, where you expected a number
you suddenly have something that is NAN - text most likely.
The error is being generated when you promised Oracle that
data would be numeric and it now isn't.
Parsing CSV files can be exceptionally difficult, especially
when freeform fields are involved. I do not know if any of
the Text::?sv modules can help, but they will likely do better
than a simple split().
If the modules are not an option, then try putting everything
into an array and check the number of elements after the split.
You can then attempt to fix it ( which I wouldn't recommend )
or kick the record out as an exception and let a human figure
it out ( which I would recommend ). Something like this:
foreach $rec ( @CUSTDATA ) {
chomp $rec;
my @data = split /,/, $rec;
if ( @data > 14 ) {
warn "Record $. has too many fields - skipping: $rec\n";
next;
}
}
mikfire
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.