Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re^3: Process and combine two CSV files into one

by Thargor (Scribe)
on Aug 09, 2005 at 21:23 UTC ( #482436=note: print w/replies, xml ) Need Help??

in reply to Re^2: Process and combine two CSV files into one
in thread Process and combine two CSV files into one

hmmm if you are just wondering on how to print to a csv file you can just use the IO::File and Text::CSV_XS. If you go check out the documentation of Text::CSV_XS and IO::File what happens is that you scan in your csv file 1 line at a time and each line is put into an array. Anyways, you can do something like

use Text::CSV_XS; use IO::File; use strict; my $csv = Text::CSV_XS->new({sep_char => "\t"}); my %hashed; open my $in, '<', $input1 or die "Read Failed: $!\n"; while(<$in>) { $csv->parse( $_ ) or warn "Bad data: $_\n", next; my @row = $csv->fields(); $hashed{ $row[0] } = \@row; } close $in; my $fh = new IO::File "> $output"; foreach my $hash ( %hashed) { if($hashed{$hash}) { $csv->combine(@{$hashed{$hash}}); print "$hash has data $hashed{ $hash }->[0]\n"; $fh->print($csv->string, "\n"); } } $fh->close;

This is just a basic read in of a csv file that is tab separated. All of the input and csv manipulation can be found in Text::CSV_XS documentation. But to output the file in csv format the easiest way I found was with IO::File.

Replies are listed 'Best First'.
Re^4: Process and combine two CSV files into one
by DrAxeman (Scribe) on Aug 09, 2005 at 21:44 UTC
    Great suggestion, but I don't think it's what I'm looking for. Then again, maybe I don't understand what you've given me. I'm using SQL to combine my CSV files based upon whats in them. The array that's created is what I need to print out. how can I use your example to print out the table in my array?

      Ah sorry didn't notice that you were using only SQL data stuff. My suggestion was only if you need to do some compare and combining of csv files outside of a database.

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2023-12-01 07:26 GMT
Find Nodes?
    Voting Booth?

    No recent polls found