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)'

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.

especially the require thing i support. consistency is important.

use Module::Load; load Foo => qw(a b);

I suspect the reason require() does not imply import() is that most of the time it does you no good to import something at run time. Contrast the results of

use 5.010;
use strict;
use warnings;
use Cwd qw{ cwd };
say cwd;

with the results of

use 5.010;
use strict;
use warnings;
require Cwd;
Cwd->import( 'cwd' );
say cwd;

and you'll see what I mean.

Leave a comment

About Steven Haryanto

user-pic A programmer (mostly Perl 5 nowadays).