On Thursday, 23 July 2015 02:09:46 UTC+5:30, T wrote:
[snip]
> But, my main sticking point is can I use "use" in a one
> liner?
But of course. The '-M' option is just what the doctor ordered.
> #!/bin/bash
> $a="$(perl -e 'use MySubs::revisions; print "blah blah")
>
> Can I get away with this?
>
> -T
You bet. Apart from a single-quote closing that you forgot to apply above.
#!/bin/bash -u
a=$(perl -MMySubs::Revisions -le 'print "bash perl"')
And in case you wanted to access the symbols (functions or vars) from the module
that are not exported by default, meaning this piece of line
use File::Basename qw( basename dirname );
will become
perl -MFile::Basename="basename,dirname" -le 'print "perl bash"'
Note: no spaces around the , or = accepted. IOW, you aren't allowed to do this
perl -MFile::Basename=" basename, dirname "
& in case you are a stickler for spaces, perl allows you to be that as well:
perl '-MFile::Basename qw/ basename dirname /'
You don't have to take my word for it ;-)
another -M command to actually verifes what
perl is doing under it's hood, so to say:
perl -MO=Deparse '-MFile::Basename qw/ basename dirname /' -e 'print dirname $ARGV[0]' /tmp/foo/perl_in_bash.sh
will return:
use File::Basename ('basename', 'dirname');
print dirname($ARGV[0]);
-e syntax OK
Do a "perldoc perlrun" on your xterm, to whet your appetite; it gives you
all the nooks & crannies of executing a perl via the command line, & that too from the horse's mouth.