[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Does a hash contain any keys other than <LIST>?



On Fri, Jun 25, 1999 at 11:01:47AM -0700, Peter Scott wrote:
> At 10:41 AM 6/25/99 -0700, Tim Allwine wrote:
> >How about somthing plain and clear...:)
> >
> >map {$mark{$_}++} @k;
> >@d = grep { !$mark{$_} } keys %h;
> >
> >print "@d\n";
> 
> 
> Well, I think we can improve a little on that, before Randal spanks you for
> the map in a void context:
> 
> @mark{@k} = ();
> print "@{[grep ! $mark{$_}, keys %h]}\n";
> 

Oops, that improvement broke the code, because now $mark{$_} is false
whether or not the key $_ exists in %mark.  Tim's code used map to increment
the value for each key, making it true.  So, to fix that...

@mark{@k} = ();
print "@{[grep ! exists $mark{$_}, keys %h]}\n";

Ronald

==== Want to unsubscribe from Fun With Perl?
==== Well, if you insist... Send mail with body "unsubscribe" to
==== fwp-request@technofile.org