in reply to Move data into AoH
Your latest message, quoted below, leaves me even more baffled about your problem case.
Harking back to my original question, '(w)hy an AoH? Why not simple hash?', I suggest the following approach lends itself to further transformation of the records into a simple hash (using the "value" elements as the keys) of the fields:
When executed:#!/usr/bin/perl use 5.016; use warnings; use Data::Dumper; =head vitoco's msg: vitoco says Re Re^2: Move data into AoH The data file happens to be a + JSON structure, an array of records, very like an AoH. I know how to + manage them in perl, but as text values may have the special chars i +nside, there was no simple regexpr to parse that. =cut # 1055528 my @arr; my $recsep = q(,); while ( <DATA> ) { @arr = split /$recsep/, $_; } my $i=1; for my $record(@arr) { say "\t $i: $record \n"; ++$i; } say "\n\n"; say Dumper @arr; =head vitoco: There are no newlines (I put them to show records), ww: So here's data with extra newlines removed but with (from OP) some + regex-special characters... namely, the square brackets... which vit +oco says prevent writing a "simple regexpr" -- OK, this uses split a +nd a regular expression (with<b>out</b> any post-5.8 bells and whistl +es), but the outcome isn't changed. =cut __DATA__ [{field1:value1,field2:value2,field3:value3},{field1:value4,field2:val +ue5,field3:value6},{field1:value7,field2:value8,field3:value9}]
C:\>perl D:\_Perl_\PMonks\1055528.pl 1: [{field1:value1 2: field2:value2 3: field3:value3} 4: {field1:value4 5: field2:value5 6: field3:value6} 7: {field1:value7 8: field2:value8 9: field3:value9}] $VAR1 = '[{field1:value1'; $VAR2 = 'field2:value2'; $VAR3 = 'field3:value3}'; $VAR4 = '{field1:value4'; $VAR5 = 'field2:value5'; $VAR6 = 'field3:value6}'; $VAR7 = '{field1:value7'; $VAR8 = 'field2:value8'; $VAR9 = 'field3:value9}]';
Am I hopelessly off target with respect to your intent? If so, can you explain more clearly for the guy (\me) currently playing 'village idiot'? (Remember, every village needs one.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Move data into AoH
by vitoco (Hermit) on Sep 26, 2013 at 13:39 UTC | |
by ww (Archbishop) on Sep 26, 2013 at 19:13 UTC | |
by vitoco (Hermit) on Sep 26, 2013 at 22:18 UTC |