Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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


In reply to Re: Re: Extra Stuff by mikfire
in thread Extra Stuff by qball

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-24 00:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found