Next: , Previous: , Up: Perl   [Contents][Index]


15.5.18.7 カッコを使用すべきとき

Perlでは、関数の引数を囲うカッコは、ほとんどの場合は任意です。常にxgettextは、すべての認識されたキーワード(hashおよびhash referencesにたいするものは除く)を、適切にプロトタイプされた関数の名前とみなし、(願わくば)Perl自体がカッコを必要とする場所だけにカッコが必要です。それゆえ、以下の例の構築例はすべて使用できます:

print gettext ("Hello World!\n");
print gettext "Hello World!\n";
print dgettext ($package => "Hello World!\n");
print dgettext $package, "Hello World!\n";

# The "fat comma" => turns the left-hand side argument into a
# single-quoted string!
print dgettext smellovision => "Hello World!\n";

# The following assignment only works with prototyped functions.
# Otherwise, the functions will act as "greedy" list operators and
# eat up all following arguments.
my $anonymous_hash = {
   planet => gettext "earth",
   cakes => ngettext "one cake", "several cakes", $n,
   still => $works,
};
# The same without fat comma:
my $other_hash = {
   'planet', gettext "earth",
   'cakes', ngettext "one cake", "several cakes", $n,
   'still', $works,
};

# Parentheses are only significant for the first argument.
print dngettext 'package', ("one cake", "several cakes", $n), $discarded;