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

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

Comment on Re: How to print after using getline_hr (Text::CSV_XS)?
Select or Download Code
Replies are listed 'Best First'.
Re^2: How to print after using getline_hr (Text::CSV_XS)?
by vagabonding electron (Hermit) 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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2015-11-27 06:34 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (719 votes), past polls