-2

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

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

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

4

1 回答 1

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;
于 2013-08-11T06:39:01.287 回答