in reply to copying bash variables into a Perl script

Here are 2 ways:
  • Comment on Re: copying bash variables into a Perl script

Replies are listed 'Best First'.
Re^2: copying bash variables into a Perl script
by ikegami (Patriarch) on Jun 15, 2010 at 20:14 UTC
    Examples:

    pass them onto your Perl script command line

    $ perl -le'print $ARGV[0]' 'Hello, World!' Hello, World!
    $ FOO='Hello, World!' $ perl -le'print $ARGV[0]' "$FOO" Hello, World!

    set environment variables in your bash script

    $ FOO='Hello, World!' $ export FOO $ perl -le'print $ENV{FOO}' Hello, World!
    $ export FOO='Hello, World!' $ perl -le'print $ENV{FOO}' Hello, World!
    $ FOO='Hello, World!' perl -le'print $ENV{FOO}' Hello, World!
Re^2: copying bash variables into a Perl script
by Xilman (Hermit) on Jun 16, 2010 at 11:27 UTC

    Here is another but rather silly way: have the Perl script read the source of the bash script and extract the names and values of the bash variables.

    The only advantage I see of this approach over your suggestions is that the Perl script needs only to know the name of the bash script. It does not need to know either the number or the names of the bash variables.

    Paul

Re^2: copying bash variables into a Perl script
by Anonymous Monk on Jul 18, 2014 at 10:20 UTC
    i have a shell script and perl script in different paths i have exported a variable name in sh script and referencing it in perl script using %ENV. But still i get error as uninitialised value am i supposed declare the shell script path in anyway lik how we use "require" and "use" or is there any other way of coding it? please help me in getting the solution for it.