CSV files are two dimensional (lines of fields). Your data is also two dimensional. To parse your data as a CSV file, each hash element would need to be parsed as a line.
use strict; use warnings; use Data::Dumper qw( Dumper ); use Text::CSV_XS 0.74; # eol bug fix. my $csv = Text::CSV_XS->new({ binary => 1, sep_char => ':', eol => ',', }); while (<DATA>) { chomp; my %h; open(my $fh, '<', \$_) or die; while (my $row = $csv->getline($fh)) { $h{ $row->[0] } = $row->[1]; } $csv->eof or $csv->error_diag(); print(Dumper(\%h)); } __DATA__ "evt":"Login","time":"now","msg":"Login success, welcome back!"
$VAR1 = { 'msg' => 'Login success, welcome back!', 'time' => 'now', 'evt' => 'Login' };
One catch: eol doesn't work for anything but "\n" in 0.73, and 0.74 isn't out yet. (The bug has been fixed, but a release hasn't been created yet.)
In reply to Re: Issue parsing CSV into hashes?
by ikegami
in thread Issue parsing CSV into hashes?
by tx2010
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |