in reply to understanding this syntax
The => operator is a synonym for the comma except that it causes its left operand to be interpreted as a string if it begins with a letter or underscore and is composed only of letters, digits and underscores. This includes operands that might otherwise be interpreted as operators, constants, single number v-strings or function calls. If in doubt about this behaviour, the left operand can be quoted explicitly.
The arrow is stringifying your argument, and the parens prevent that behavior. You would also get your expected behavior by swapping to explicit commas:
use constant FOO => 10; use constant BAR => 20; %BAZ = ( FOO, 1, BAR, 1 ); sub is_baz { my $i = shift; return ( exists $BAZ{$i} ) ? 1 : 0; } .... is_baz(10);
|
|---|