3 ms·
> We will have a beautiful DSL so you don’t have to quote arguments as string... If i'm using Perl's Shell.pm (as mentioned elsewhere here by btilly) and wante
by draegtun 14y ago
> We will have a beautiful DSL so you don’t have to quote arguments as string...
If i'm using Perl's Shell.pm (as mentioned elsewhere here by btilly) and wanted to avoid quoting arguments then I could do:
use 5.016;
use warnings;
use Shell ();
use PerlX::QuoteOperator ls => {
-emulate => 'qq',
-with => sub ($) { Shell::ls($_[0]) },
};
use PerlX::QuoteOperator uname => {
-emulate => 'qq',
-with => sub ($) { Shell::uname($_[0]) },
};
use PerlX::QuoteOperator ip => {
-emulate => 'qq',
-with => sub ($) { Shell::ip($_[0]) },
};
# and then...
ls();
uname(-a);
ip(-4 addr);
But this seems to be an overkill because I could just use Perl's backticks (http://perldoc.perl.org/perlop.html#Quote-Like-Operators http://perldoc.perl.org/perlop.html#Quote-Like-Operators)...
`ls`;
`uname -a`;
`ip -4 addr`;
And it works with variables...
my $x = "/usr/local/";
my $files = `ls -l $x`;
and piping...
my $perl_files = `ls | grep .pl`;
Shell.pm also works with variables & piping but I think that backticks are probably Perl's best DSL for dealing (easily) with shell stuff :)