Nit: sub name {...} is almost equivalent to BEGIN { *name = sub {...}; }. The latter has no name associated with it, which matters in traces.
$ perl -e' use Carp qw( croak ); sub foo { croak "bar" } foo(); ' bar at -e line 3. main::foo() called at -e line 4
$ perl -e' use Carp qw( croak ); BEGIN { *foo = sub { croak "bar" }; } foo(); ' bar at -e line 3. main::__ANON__() called at -e line 4
There are ways of naming the anon sub to get a BEGIN-using equivalent.
$ perl -e' use Carp qw( croak ); use Sub::Util qw( set_subname ); BEGIN { *foo = set_subname "foo", sub { croak "bar" }; } foo(); ' bar at -e line 4. main::foo() called at -e line 5
In reply to Re^3: create an anonymous hash using "map" (BEGIN block References)
by ikegami
in thread create an anonymous hash using "map"
by raygun
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |