On 21 Jan 2002, at 15:54, Robin Houston wrote:
> On Mon, Jan 21, 2002 at 10:50:06AM -0500, Bernie Cosell wrote:
> > On 21 Jan 2002, at 15:12, Simon Cozens wrote:
> > > On Mon, Jan 21, 2002 at 03:00:57PM +0000, Robin Houston wrote:
> > > > In an ideal world it would behave the same as
> > > > %a = (%b, %c);
> > > > for my $k (keys %a) {
> > > > $a{$k} += $b{$k} if exists($b{$k}) && exists($c{$k});
> > > > }
> > >
> > > It's not impossible that it would end up doing just that.
> >
> > [...]
> >
> > [this being a sort of inner-join, and if you like you could have
> > something like an outer-join, where the non-exists element of the other
> > hash would be treated as a '0'.]
>
> My code snippet was supposed to implement the "outer join" idea.
> Are you saying that it doesn't?
I don't think it does, but we may be having a terminology problem [and
indeed, as I mentioned I may be misunderstanding what the original:
@a = @b ^+ @c
is supposed to do and mis-analogizing to %a = %b ^+ %c
First, it is an *assignment* [at least to my eye], and so any solution
that doesn't begin with "undef %a" isn't going to have 'join' semantics
[at least as I understand joins]. What I wrote is an inner join [there
will be keys in %a ONLY IF there are corresponding keys in both %b and
%c, and the value will be the sum of the two associated values]. To make
it an outer join [where there is a key in %a if *EITHER* hash as a key],
the code would have to be something like:
undef %a ;
for my $k (keys %{{%b,%c}}
{ local $^W ; $a{$k} = $b{$k} + $c{$k} ; }
/Bernie\
--
Bernie Cosell Fantasy Farm Fibers
mailto:[EMAIL PROTECTED] Pearisburg, VA
--> Too many people, too few sheep <--