in reply to Re: Read CSV with column mapping
in thread Read CSV with column mapping
Thanks. Following I am providing ReadCSV.pm, parameters.csv and getvalue.pl. It is working fine but I want to avoid any comments (starts with #) in parameters.csv and also any blank lines. How can I do that in ReadCSV.pm ?
ReadCSV.pmparameters.confpackage ReadCSV; use strict; use warnings; use Data::Dumper; use Text::CSV_XS; use IO::File; # Implementation: sub csv_file_hashref { my ($filename) = @_; my $csv_fh = IO::File->new($filename, 'r'); my $csv = Text::CSV_XS->new (); my %output_hash; while(my $colref = $csv->getline ($csv_fh)) { $output_hash{shift @{$colref}} = $colref; } return \%output_hash; } 1;
getvalue.plabc xyz,10 xyz pqr,2 pqr stq,0.1
use strict; use warnings; use Data::Dumper; use ReadCSV; my $hash_ref = ReadCSV::csv_file_hashref('parameters.conf'); foreach my $key (sort keys %{$hash_ref}){ print qq{$key:}; print join q{,}, @{$hash_ref->{$key}}; print qq{\n}; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Read CSV with column mapping
by Corion (Patriarch) on Dec 14, 2018 at 22:44 UTC | |
by coretele (Novice) on Dec 16, 2018 at 02:11 UTC | |
by huck (Prior) on Dec 16, 2018 at 06:15 UTC | |
by AnomalousMonk (Archbishop) on Dec 16, 2018 at 06:31 UTC | |
by coretele (Novice) on Dec 16, 2018 at 17:59 UTC | |
by Tux (Canon) on Dec 17, 2018 at 07:59 UTC | |
| |
by poj (Abbot) on Dec 16, 2018 at 18:17 UTC | |
| |
by huck (Prior) on Dec 16, 2018 at 18:22 UTC |