in reply to passing a variable from shell script to the main perl

Just use backticks.

my $results = `shell.sh`;

Changes to your %ENV made by the shell script will not persist when you return to the perl script. Similarly, changes to the %ENV by your perl script will not stay when it ends either. Although there are "tricks" one can do in theory.

Replies are listed 'Best First'.
Re^2: passing a variable from shell script to the main perl
by vbynagari (Initiate) on Apr 05, 2011 at 22:09 UTC
    Can you please elaborate on this? I am not quite following you. thx

      How are you calling your shell script? Are you using system?

      system("shell.sh");

      Any changes that your shell.sh script makes to the %ENV will not stay after the system command is finished. Instead, simply have your shell.sh script echo some text that your perl script can capture when using backticks.

      my $results = `shell.sh`; if ($results =~ /Hello World/) { print "tada!"; }
      shell.sh
      echo "Hello world";
        <text>when I do this </test>  $xx=`sh $translationscript $filename $source_dir $file 2>&1`; <text> the value $xx has the log from the shell script and the STDOUT. Also, in the shell, I am checking for some errors and based on the error - I have a variable defined and I want that variable need in perl and then I will have to continue my script based upon the type of error I get from the shell. How do I do this? </text> thx