Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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
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 :-))
    VE

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2015-07-06 07:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (70 votes), past polls