As the previous posters indicate, we're forced to do a bit of guessing as to what you want. I'm guessing you want to save the data to disk and retrieve it again. Below is code to write your data to a flat file, then read it. Two things to note.

1.) Since there are newlines in the data, you can't use newline to separate fields on the disk. If your data is all printable ascii, you can use a non-printable char other then newline to separate items. Assign this to "$/" to get Perl to do the work for you.

2.) The 3 argument version of split() is less common, but very useful to know. In the case below, it splits into 2 fields only, so you just pull off the first field, the key, leaving all the separators in the second field in place.

my $blank = ' '; my $fldSep = "\x1c"; my $recSep = "\x1e"; my $SAV; my $RETRIEVE; open $SAV, '>', 'tempsav.hsh' or die "Can't open save file"; store_rec($VAR1); store_rec($VAR2); close $SAV; sub store_rec { my $hashRef = shift; my ($key,$val); while (($key,$val) = each %$hashRef) { $val = '' if !defined $val; # guard against non=printing fld/rec sep in values $val =~ s/$fldSep/?/g; $val =~ s/$recSep/?/g; print $SAV "$key $val$recSep"; } print $SAV $fldSep; 1; } # store open $RETRIEVE, '<', 'tempsav.hsh' or die "Can't open save file"; $/ = $recSep; while (<$RETRIEVE>) { my ($key,$val); $_ =~ s/$recSep$//; for my $fld (split $fldSep, $_) { ($key,$val) = split(' ',$fld,2); # Remove rec sep in values print "$key => |$val|\n"; } } close $RETRIEVE;
By the way, I'm sure what you meant to say to daveorg was "Oops, here's what I meant...", since no one wants to help someone who dismisses those they have asked for help. If you still think you said what you meant, then you probably should swallow your pride, calm down, and read the other replies, since their advice will be far more valuable in the long run then the coding suggestions I've offered you above.

Good luck.


In reply to Re: array of hashes by rodion
in thread array of hashes by perumal

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.