Newbie external script return question.

From: Jimmy Phillips (sendto_at_spammers.com)
Date: 09/07/04


Date: Tue, 07 Sep 2004 15:42:12 +0200

I am playing with how to call external scripts but can't get the return
value. Example

Caller script...
*************
#!/usr/bin/perl -w
use strict;
        my $result = `./dice.pl 5`;
        print $result . "\n";

The called script...
*************
#!/usr/bin/perl -w
use strict;
my $randresult;
        $randresult = rand $ARGV[0];

If I run the called script with a commandline ./dice.pl 30 it works fine.
The caller script calls ok but gets back an undef. Obviously because
nothing got returned.

Question, how do I specify the $randresult to be a return value? The
keywork "return" is no good outside of a subroutine.

What am I missing?

Thanks
JP



Relevant Pages

  • Re: Critcize my scripts.
    ... > (I know it's a good practice to put use strict in Perl ... > use strict.The script below work fine if I comment out ... perldoc -f use ... Sub Routines ...
    (perl.beginners)
  • Re: [PATCH] Speed up "make headers_*"
    ... 'use strict' and 'use warnings' is recommended. ... The parentheses are not needed for most of the built-in functions. ... More or less the same comments would apply to the next script as well. ...
    (Linux-Kernel)
  • Re: tricky list comparison problem
    ... > I'm having a bit of an issue with a script I'm working on. ... > - 69078878" as available sectors. ... > use strict(); ... You are telling perl to load the 'strict' module and then you are telling the ...
    (perl.beginners)
  • Re: Passing vars to a "require"d script
    ... > require'd script didn't seem to pull in the form data, ... >> use strict; ... >> use warnings; # main program ...
    (comp.lang.perl.misc)
  • Re: Regular Expression and file editing.
    ... Goksie wrote: ... If i run the script, the changes could not be effected bcos the files is ... use warnings; ... use strict; ...
    (perl.beginners)