in reply to understanding this syntax

Without the parens, you'd get %BAZ = ('FOO', 1, 'BAR', 1); due to the autoquoting behaviour of =>. The author wanted %BAZ = (10, 1, 20, 1);. Each of the following achieve the desired results:

%BAZ = ( FOO, 1, BAR, 1 ); %BAZ = ( (FOO) => 1, (BAR) => 1 ); %BAZ = ( FOO() => 1, BAR() => 1 );

The last requires knowing that constants can be called like functions. I prefer the middle version. Actually, no. I'd use the following since it eliminates redundancies and illustrates the intent better:

%BAZ = map { $_ => 1 } FOO, BAR;

By the way,

sub is_baz { my $i = shift; return ( exists $BAZ{$i} ) ? 1 : 0; }

can be simplified to

sub is_baz { my $i = shift; return $BAZ{$i}; }

Replies are listed 'Best First'.
Re^2: understanding this syntax
by Anonymous Monk on Oct 01, 2010 at 20:00 UTC
    Thanks for the great explanation tpo both of you guys!!!