On Thu, Oct 6, 2016 at 6:07 PM, Tony Cook <tony@develop-help.com> wrote: > > It doesn't: > > $ perl -MData::Dumper -e 'sub x {} %x = ( foo => x() => bar => 1 ); print > Dumper(\%x)' > $VAR1 = { > 'foo' => 'bar', > '1' => undef > }; > > => only differs from the comma operator in that it quotes identifiers > given as its left argument. > Drat. Wrapping in scalar works though: $ perl -MData::Dumper -e 'sub x {} %x = ( foo => scalar(x()) => bar => 1 ); print Dumper(\%x)' $VAR1 = { 'bar' => 1, 'foo' => undef }; Also, if you're following the Best Practice of naming all the values prior to constructing hashes, you can leave things out with the ternary operator without it being that unclear: $ perl -MData::Dumper -e 'sub x {} %x = ( ( $foo ? (foo => $foo) : ()), bar => 1 ); print Dumper(\%x)' $VAR1 = { 'bar' => 1 }; -- "Teaching radical novelties is our main safeguard against dictatorships" -- Edsger W. DijkstraThread Previous | Thread Next