http://www.perlmonks.org?node_id=937055


in reply to How to print after using getline_hr (Text::CSV_XS)?

Your first script uses a very convoluted way to construct the output. You use arrays to store simple scalar variables. You use loops where only a single value is concerned. You process the CSV file line by line, but somehow seem to think that you process a whole column at a time.

#loop from your first script: while ( my $hr = $csv->getline_hr( *DATA ) ) { my $nr = $hr->{'ID'}; $nr=~ s/12/Sun/; # neither the g nor the loop are necessary $nr=~ s/17/Moon/; my $name = $hr->{'NAME'}; # only one value in column NAME of this +line my $ind = $hr->{'INDICATOR'}; my $val = $hr->{'VALUE'}; my $low = $hr->{'CI_LOW'}; my $high = $hr->{'CI_HIGH'}; if ($csv->combine ( $nr, $name, $ind, $val, $low, $high)) { print $csv->string, "\n"; } else { print "combine () failed on argument: ", $csv->error_input, "\n"; } }

Likewise "$hr->{'ID'}=~ s/12/Sun/;" could be used in your second script and the print adapted like Tux suggested

Replies are listed 'Best First'.
Re^2: How to print after using getline_hr (Text::CSV_XS)?
by vagabonding electron (Curate) on Nov 09, 2011 at 13:13 UTC
    Thank you very much jethro I seem to understand it better now (well, at least I hope so :-))
    VE