Ok. Now I get it. :-) Personally I would return very different results...
# Determines if two hashes have different keys # If the hashes are different: # In list context returns two array refs, each # containing the missing elements from the other # In scalar context returns an AOA, with a similar # content as above # Otherwise # Returns the empty list or undef as appropriate. # Thus # A true return means they hashes are different, # a false means they have identical keys sub hash_key_diff { my ($x,$y)=@_; my (@x,@y); foreach my $k (keys %$x) { push @y,$k unless exists $y->{$k}; } foreach my $k (keys %$y) { push @x,$k unless exists $x->{$k}; } return @x||@y ? wantarray ? (\@x,\@y) : [\@x,\@y] : () }
This seems like a much more reasonable return to me, and considering the use you put it to it would seem to be more convenient as well: this would give you a list of processes that have been removed, as well as processes that have started.
BTW: You didnt overlook my point about the sort order did you?
Anyway, thanks for the explanation.
In reply to Re: Re: Re: Comparing all keys in a hash
by demerphq
in thread Comparing all keys in a hash
by rinceWind
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |