Here's an example of a recurrent annoyance:
my $package = 'Foo::Bar::Baz';
(my $package_filename = $package) =~ s,::,/,g;
require $package_filename;
$package->foobar();
One of my many neurotic little peeves is that, unless code readability
absolutely demands it, I hate defining variables that will be used
only once, such as $package_filename above. I would like to be able
to do something like
my $package = 'Foo::Bar::Baz';
require TRANSFORM[ s,::,/,g, "$package.pm" ];
$package->foobar();
where TRANSFORM[] stands for an expression in which an "s-expression"
(i.e. one using s///) is applied to a string, and the resulting string
is returned as the result.
Of course, I could define a helper sub to do this:
sub transform {
my $s_expression = shift;
local $_ = shift;
eval $s_expression;
die $@ if $@;
$_
}
But is there a way to achieve this result without defining such a
helper sub?
kynn
P.S. I couldn't come up with a sufficiently general transform sub such
that its first argument is a qr-quoted regexp. Is there a way to do
this that approaches the level of generality of the eval kluge above?