in reply to Re: return the output to the Parent script
in thread return the output to the Parent script

I tried backticks also. It gives the following message and returns nothing.
Err:<code> Can't return outside a subroutine at ..<\code>
  • Comment on Re^2: return the output to the Parent script

Replies are listed 'Best First'.
Re^3: return the output to the Parent script
by Corion (Patriarch) on Sep 22, 2008 at 09:11 UTC

    This has nothing to do with backticks. As you're not showing any code that reproduces the problem, I can't help you further. Maybe consider posting self-contained code that exhibits the problem.

    That error message mostly happens if you have a program like the following:

    #!/usr/bin/perl -w use strict; return 'Hello';

    So you must be doing that somewhere in your code.

      Yes I do.

      Sorry for not giving sufficient info.
      Here is my requirement.

      1.Call another(child) script which process a text file and return a value to the main script.

      I am calling the second script frm main like this.

       my $cmd=" perl C:\\ia\\getset_build_num.pl -mode get -p $outputname -t $build_num_template -c $build_num_config";
      In the second script, I capture the cmd input,exec subroutine and return the value to the main script. Problem arises when returning the value to main script. I am wrong when returning the value. if so what will be the correct value.

      if ($mode eq "get") { my ($bld_num,$message)= get_build_number($package,$config_file); return $bld_num; }else{ my ($set_status,$message) = set_build_number($package,$template,$c +onfig_file); return ($set_status,$message); }
      Thanks

        A Perl program that you call via backticks to process its output is just like any other program. It has to print the output. Using return does not work. Your child Perl program does not work alone, so it won't work when called via backticks or system either.

        If you want to structure your programs and keep common parts in a single file, look at do or require to load Perl code from files and call the common code as a subroutine.

Re^3: return the output to the Parent script
by moritz (Cardinal) on Sep 22, 2008 at 09:23 UTC
    If you want to pass data around in perl data structures, turn your script into a module, then you can ordinarily return data from it.