Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re^8: Processing CSV File

by Kenosis (Priest)
on Oct 05, 2012 at 04:45 UTC ( #997373=note: print w/replies, xml ) Need Help??

in reply to Re^7: Processing CSV File
in thread Processing CSV File

Are you able to install Perl Modules? If so, install Text::CSV, and let me know when this is done.

There are two reasons that the Module may serve you well in this case. The first is that it's generally a best practice to use a Module that's built to handle csv files. In your case, the csv format wasn't complex, i.e., commas within quoted fields, so just splitting on commas was OK. However, thinking long-term, your data may get more complex, and Text::CSV would be able to handle it.

The second reason is based upon the error messages you shared. The variable $vars was uninitialized when it should have contained a value. This may be an issue of the csv file containing binary data, but I'm not sure. Text::CSV can handle this, too.

Let me know...

Replies are listed 'Best First'.
Re^9: Processing CSV File
by Anonymous Monk on Oct 05, 2012 at 04:58 UTC

    Thanks for the reply Kenosis
    I was trying to steer clear of installing modules, as the script could be used on different machines at any time all over the place, of which some I do not have control.. so was hoping to have a script that worked 'out of the box' on any machine.
    Do you think there would be any way around it?
    If there really is no other way, then perhaps I will need to explore that option.. but would prefer not to if at all possible

      Give the following change a try:

      open my $csvfh, '<:crlf', $csvFile or die "Unable to open $csvFile: $! +"; ^ | + - Add the :crlf

        Same error as before..

        Use of uninitialized value $vars in chomp at line 18 +, <$csvfh> line 1. Use of uninitialized value $vars in split at line 19 +, <$csvfh> line 1.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://997373]
[Discipulus]: indeed marto I dunno. I tested once and many years ago. But I'm not the programmer yardstick. I try to install Padre via cpan now just to add a line about it in the issue. Strawberryperl all life long!
[marto]: yeah, when I worked on Windows I did use Np++ all the time

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (11)
As of 2018-06-25 08:56 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.