Text::CSV by hashref


/ Published in: Perl
Save to your folder(s)



Copy this code and paste it in your HTML
  1. use Data::Dumper;
  2. my $csv = Text::CSV->new ( { binary => 1 } ) # should set binary attribute.
  3. or die "Cannot use CSV: ".Text::CSV->error_diag ();
  4. open my $fh, "<:encoding(utf8)", "$infile" or die "$infile $!";
  5.  
  6. $csv->column_names ($csv->getline ($fh));
  7.  
  8. while ( my $hr = $csv->getline_hr( $fh ) ) {
  9. $hash{ $hr->{fieldA} }= $hr->{valueA};
  10. }
  11.  
  12. $csv->eof or $csv->error_diag();
  13. close $fh;
  14.  
  15. print Dumper(%hash)

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.