in reply to Re: pass perl variable to shell script
in thread pass perl variable to shell script

Thanks, morgon. But the command substitution will not work for me here. The code snippet I have is just an example to get my point across on how I can access a variable (str3 in this case) in shell after I set it in Perl.
  • Comment on Re^2: pass perl variable to shell script

Replies are listed 'Best First'.
Re^3: pass perl variable to shell script
by morgon (Priest) on Aug 11, 2010 at 16:23 UTC
    The command substuition captures the output of the perl-script at the shell-side.

    So if you only have to pass one value you simply print it to standard output in Perl.

    #in perl-script "script.pl" print $variable; #in the shell-script: variable=$(perl script.pl) echo $variable
    If you must pass more than one variable you e.g. print them in a certain format "$var1=$var2=$var3" and parse that on the shell side.
      morgon, I only have one script -- shell script, in which i have a block of perl code. Lets forget I have 'print' statement in the perl block. Lets say I am setting str3 somewhere in the middle of the perl block. After perl block has finished executing, I am back in the shell part of the code and need to get the content of str3 variable that was set in the perl block of the code. How do I do it?
        How do I do it?

        Programs communicate via STDIN/STDOUT, so the way morgon and others showed you is the way to do it

        Without changing the perl code to report the value somehow, there is no way.