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

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



>>>>> "PS" == Peter Scott <Peter@PSDT.com> writes:

PS> Given a hash %h (in my case, %h is tied, but I don't think it'll matter), I 
PS> want to know just whether it contains any keys *other* than those listed 
PS> in, say, @k. My somewhat pedestrian solution:

PS> my %t; 
PS> @t{keys %h} = (); 
PS> delete @t{@k}; 
PS> print "Yes!" if keys %t;

PS> Anything better? (Yeah, you could optimize it by testing first if @k > 
PS> keys %h, but in my case there are very few keys.)

How about:

	join(':',sort keys %h) eq join(':', sort @k)
or
	@t{@k, keys%h}=();
	scalar(keys %t) != scalar(@k);

<chaim>
-- 
Chaim Frenkel					     Nonlinear Knowledge, Inc.
chaimf@pobox.com				               +1-718-236-0183

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