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.
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.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;
Good luck.
In reply to Re: array of hashes
by rodion
in thread array of hashes
by perumal
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |