On Friday, April 26, 2002, at 03:49 , Shaun Fryer wrote:
[..]
>
> foreach $value (@array) {
> $scalar_array .= "$value|";
> }
> chop($scalar_array);
> my %hash;
> $hash{some_key} = $scalar_array;
>
> Then if you want to get the array from the key's value later
> on, you just split(/\|/,"$hash{some_key}"). I typically do this when
> writing berkley db's which need to have variable length arrays as the
> values of a list of keys. You'll have to pick a delimiter that won't
> exist within $value.
well played!
Thought I would benchmark this against the more traditional
'join' strategy - and the two basic ways I use for passing
around arrays in hashes...
http://www.wetware.com/drieux/CS/lang/Perl/Beginners/BenchMarks/loopVjoin.
txt
This did give me the chance to look at the various ways that this
could be done - and I shall leave it to others to resolve which
variation on a theme would be more consistent with their code
maintenance issues....
but you might want to look at
sub joinFunc {
my $scalar_array = join('|',@array);
$hash{$some_Other_key} = $scalar_array;
my @new_array = split(/\|/, $hash{$some_Other_key});
} # end of joinFunc
as a slightly more efficient strategy....
ciao
drieux
---
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]