Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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

by jethro (Monsignor)
on Nov 09, 2011 at 11:55 UTC ( #937055=note: print w/replies, xml ) Need Help??

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 (Chaplain) 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 :-))

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://937055]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2018-04-26 14:37 GMT
Find Nodes?
    Voting Booth?