perumal has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re: array of hashes
by davorg (Chancellor) on Jun 13, 2006 at 13:14 UTC

    You're almost certainly getting no answers because your question is vague and confused. Please read "How (Not) To Ask A Question" and try to explain your problem in more detail.

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: array of hashes
by rodion (Chaplain) on Jun 13, 2006 at 14:06 UTC
    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.

Re: array of hashes
by samizdat (Vicar) on Jun 13, 2006 at 14:11 UTC
    perumal, you need to get a clue. People ARE trying to be helpful, but you are pulling your own plug with your attitude.

    You didn't provide any idea as to what kind of a table or organization you want to end up with. If you had actually thought about it enough to write it down for us, the answer would almost certainly be a heck of a lot closer to your brain than it is now.

    Lacking any pertinent information as to what you want, the generalities are that you will need to build a table that includes the array and hash keys ($VARx and 'received_thru', etc.) as columns as well as the individual type data. Once you've done that, then you need to iterate through the array to get each reference to a hash, and then take that reference to get the array of all keys, and then iterate through that set. What you do with those results can be to generate an SQL CREATE TABLE/INSERT INTO set, an HTML table <TR><TD> set, or whatever else you need.

    Don Wilde
    "There's more than one level to any answer."
Re: array of hashes
by Joost (Canon) on Jun 13, 2006 at 13:15 UTC
Re: array of hashes
by xorl (Deacon) on Jun 15, 2006 at 15:58 UTC