How do I carry my variables from a Bash script into a Perl one?
Making variables available to child process in shell script can be done either by exporting variables
export foo=bar
Or by calling program with variables prepended
foo=bar ./my_prog.pl
In either case you will need to call ENV
on them inside perl script
my $barfoo = $ENV{'foo'};
Using the environment is a cleaner way.
There is the -s
switch:
$ cat vars.pl
#!perl
use feature 'say';
say "foo=$foo";
say "bar=$bar";
$ echo "$foo,$bar"
123,456
$ perl -s ./vars.pl -foo="$foo" -bar="$bar"
foo=123
bar=456