Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Best method of munging CSV data - using Text::CSV::Simple?

by jZed (Prior)
on Feb 08, 2006 at 06:00 UTC ( #528732=note: print w/replies, xml ) Need Help??


in reply to Best method of munging CSV data - using Text::CSV::Simple?

I'm not quite sure I understand where you're getting stuck, but it sounds like you have already done the CSV parsing bit - you're able to break each line into a series of fields. You also sounds like you know how to go about munging out the data you want from each field. So my best guess is that where you are stuck is with how to get data into and out of perl data structures.

The @data that you get from Text::CSV::Simple is an array of array references. That means that each item in the array is itself a reference to an array composed of three fields. That means you need to derefernce it to get at the fields like this:

for my $row(@data){ my($smtp,$user,$server) = @$row; # munge $stmp next unless $smtp; # munge $user and $server # recombine them into a string # write the string to a file }
If I've misunderstood the part you're having a problem with, let me know.

Replies are listed 'Best First'.
Re^2: Best method of munging CSV data - using Text::CSV::Simple?
by billie_t (Sexton) on Feb 08, 2006 at 06:23 UTC

    No, that's correct - I was getting my knickers in a knot trying to figure out when I do the munging and output to a file. So what I essentially need to do here is read a row at a time, fiddle around with it and output it before working on the next line. I knew that logically, but couldn't figure out the forest for looking at the trees.

    Thank you for breaking down what I need to do structurally - I have real problems with that aspect of coding (infrequent use). I think I have enough from you and Cody Pendant to be able to figure it out from here.

Re^2: Best method of munging CSV data - using Text::CSV::Simple?
by Scott7477 (Chaplain) on Feb 05, 2007 at 23:02 UTC
    "The @data that you get from Text::CSV::Simple is an array of array references. That means that each item in the array is itself a reference to an array composed of three fields. That means you need to derefernce it..."
    This is need to know information that isn't made that clear in the module docs. I've annotated the CPAN module with a paraphrase of your explanation.
    Thanks,
    I have been butting my head for a few minutes trying to get some code using this module to work. Update: this reply was intended for jZed, I fat fingered the post.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2021-07-29 12:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?