One way to be sigil-less

作者:   發佈於:  

It is possible to write such sigil-less perl program:

foo = 42;
say foo;

The trick is to declare foo as a lvalue sub:

my $foo;
sub foo :lvalue { $foo }

Since $foo is a scalar, it works for hashref and arrayref too:

foo = { ans => 42 };
say foo->{ans}
# => 42

foo = [42, 43, 44]
say foo->[0]
# => 42

This appears to me an interesting smell of a new PerlX module.