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:

#!/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}]
When executed:
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.)


In reply to Re: Move data into AoH by ww
in thread Move data into AoH by vitoco

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.