Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: CSV SPLIT

by serene_monk (Initiate)
on Jun 21, 2013 at 05:27 UTC ( [id://1040070]=note: print w/replies, xml ) Need Help??


in reply to Re: CSV SPLIT
in thread CSV SPLIT

Thank you for replying

hey the thing is , my code wants to work on formatting the structure of the csv data , so I need to split it into words and with help of some specific words I have to do the formatting . I have each column of csv(as seen by excel ) in an array , via split function . this works absolutely fine when there is no user input ,

I think this cpan , only aims to convert csv to text directly

Replies are listed 'Best First'.
Re^3: CSV SPLIT
by space_monk (Chaplain) on Jun 21, 2013 at 05:37 UTC

    As kcott posted, there are almost no circumstances where you should use split to retrieve or store CSV data due to problems similar to those you've encountered. Text::CSV and its close relatives will happily get/put data between a CSV file and an array, and deal with the separators in data properly by quoting them. Once the row is in the array you can process it anyway you like.

    If you post some example data and what you'd like to happen to it, perhaps we can give you a more detailed answer. Don't forget to use <code> tags to show your data in the question properly

    If you spot any bugs in my solutions, it's because I've deliberately left them in as an exercise for the reader! :-)

      hey the cpan gives an error that says " Expected fields to be in an array "

      and the line is

      $status = $csv->print ($io, $colref);

        Well, is $colref a reference to an array in your code or not?

        Post your code and some data, you can modify your original question to do this.

        If you spot any bugs in my solutions, it's because I've deliberately left them in as an exercise for the reader! :-)
Re^3: CSV SPLIT
by kcott (Archbishop) on Jun 21, 2013 at 06:56 UTC

    I concur with the advice space_monk has given you. We get these types of questions every day or two: search in Super Search for Text::CSV or, if you prefer, here's one I prepared earlier :-)

    Some additional information:

    • CPAN (uppercase) stands for Comprehensive Perl Archive Network. It's a searchable repository of Perl modules.
    • cpan (lowercase) is a command line utility for interacting with CPAN. You get this for free: it's installed when you install Perl. When you write "cpan" in your posts, this is what people will think you are referring to.
    • When you wish to refer to a CPAN module, you should do so by name. It's helpful to provide a link to the module in question, as I did in my original reply to you. There's Shortcuts for doing this.
    • Don't reply to yourself as you did with (Re^2) "... csv to text directly" (Re^3) "and i was thinking ..."; just edit your post as explained in "How do I change/delete my post?".
    • In order to get the best possible responses to your questions, follow the guidelines in "How do I post a question effectively?".

    -- Ken

Re^3: CSV SPLIT
by serene_monk (Initiate) on Jun 21, 2013 at 05:36 UTC

    and i was thinking is it possible to convert comma to any special char while reading and change it back to comma while printing

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1040070]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-19 19:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found