Random Perl wishlists #1: uncapture modifier, require+import, backtick function
Uncapture modifier. The new /r regexp substitution modifier in Perl 5.13.2 indicates that there might be hope for even more modifiers in the future. A possible modifier might be one that ignores all capture groups, which can solve this guy's problem.
require that can also import. I wonder why "require" doesn't also support importing like "use" does: use MODULE_NAME LIST... since it already support "require MODULE_NAME". This way, whenever I want to defer loading some modules, I can just replace "use" with "require" and put the statement under some "if" statement.
the backtick function.. Do you find yourself often having to do use a temporary variable like this, $cmd = "some longish and ".quote("complexly formed")."command"; before doing backtick `$cmd`? This is because unlike in PHP, we have system() but no backtick(). Most probably remnants from shell. There is Capture::Tiny for more general solution but of course it's a bit more cumbersome.
$ perl -E 'print qx(ls *.pl)'
foo.pl
It's pretty easy to load and import modules at runtime. We don't need anything additional to do that.
I'm not sure what you mean by a backtick function. You can already interpolate subroutine calls into strings.
@coke, brian: What I meant is when we want to use string expression (instead of just simple string or string substitution) fed to backtick. But I totally forgot about this (reminded by zloyrusskiy in a comment on my other blog): `${\ "some longish and ".quote("complexly formed")."command" }` so let's scratch this one out.
@brian: Yup, currently to load a module at runtime we can always do 'eval "use Foo qw(a b)"' or 'require Foo; Foo->import(qw(a b))' but I suspect beginners will join me in asking why can't we do 'require Foo qw(a b)' also.
especially the require thing i support. consistency is important.
use Module::Load; load Foo => qw(a b);
I suspect the reason
require()does not implyimport()is that most of the time it does you no good to import something at run time. Contrast the results ofuse 5.010; use strict; use warnings; use Cwd qw{ cwd }; say cwd;with the results of
and you'll see what I mean.
@Tom: makes sense. I don't even remember now why I wanted require to do import. Probably because there's some custom initialization code in some module that needs to be called. Which is a specific case anyway.