密钥如何成为哈希值的一部分?

时间:2013-08-11 06:22:50

标签: perl

以下是我的哈希。我不想在值部分重复密钥(city& country)。

%sql_cache = (
city => "select * from city where id=106",
country => "select * from country where code='IND'",
);

是否有任何内置变量可以在Perl中实现?

1 个答案:

答案 0 :(得分:3)

怎么样?

my %sql_cache = (
    city => "select * from %s where id=106",
    country => "select * from %s where code='IND'",
);

# use it
printf "$sql_cache{$_}\n", $_ for keys %sql_cache;