in reply to Issue parsing CSV into hashes?
Just using split as suggested by others. Potentially rather fragile but this works for your example text. Some form of parsing solution would be more robust, especially if you have to cope with spaces around delimiters or escaped embedded quotes.
knoppix@Microknoppix:~$ perl -E ' > $str = q{"evt":"Login","time":"now","msg":"Login success, welcome ba +ck!"}; > %hash = > map { split m{:} } > split m{(?<="),(?=")}, $str; > say qq{$_ => $hash{ $_ }} for keys %hash;' perl: warning: Setting locale failed. "msg" => "Login success, welcome back!" "evt" => "Login" "time" => "now" knoppix@Microknoppix:~$
I hope this is helpful.
Cheers,
JohnGG
|
|---|