in reply to printing CSV to file?

Here's some code I've used to print to a CSV file:
# $csv is an instance of Text::CSV_XS # $fh is an IO::File filehandle # %data is a row of data # @outcols corresponds to the keys of %data I want $csv->combine(@data{ @outcols }) || die "choked on: '@{[ $csv->error_input ]}'\n"; $fh->print($csv->string,"\n");

Replies are listed 'Best First'.
Re^2: printing CSV to file?
by Thargor (Scribe) on May 10, 2005 at 16:43 UTC
    Your code looks like a good solution to what I am doing however, I dono't think I have my data in a form that would work with that solution. my $csv is a Text::CSV_XS class I am reading in my data into hash that has keys that point to array refs. So I am reading in data like so:
    while(<$in>){ $csv->parse( $_ ) or warn "Bad data: $_\n", next; my @row = $csv->fields(); $hashed{ $row[ 0 ] } = \@row; }close $in;

    Update:Nevermind I was just being and idiot. Your solution worked great once I understood it thanks.