Chinaunix

标题: Hash表之间键比较 [打印本页]

作者: romario94    时间: 2007-11-28 16:31
标题: Hash表之间键比较
let's say I have two hash tables: new, old

How to find out the keys in new, but not in old?
How to find out the keys in old, but not in new?

tell me the quickest way.

Thanks.
作者: 放驴娃    时间: 2007-11-28 16:52
use List::MoreUtils;
作者: Lonki    时间: 2007-11-28 19:10
my %ha = (a => 1, b => 2, c => 3);
my %hb = (a => 4, d => 5, e => 6);

### keys in ha but not in hb ###
my @list = grep {! exists $hb{$_}} keys %ha;
print @list;




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2