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

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



At 10:41 AM 6/25/99 -0700, Tim Allwine wrote:
>Peter Scott said...
>>
>>Given a hash %h (in my case, %h is tied, but I don't think it'll matter), I 
>>want to know just whether it contains any keys *other* than those listed 
>>in, say, @k. My somewhat pedestrian solution:
>>
>>my %t; 
>>@t{keys %h} = (); 
>>delete @t{@k}; 
>>print "Yes!" if keys %t;
>>
>
>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";

Peter Scott
Pacific Systems Design Technologies



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