Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return value from a Perl script

Is it possible to return a value (or hashes or arrays) from a Perl script invoked by another?

File caller.pl

printf("%d", system("callee.pl"));

File callee.pl

if(<Went good>)
{
    return(1);
}
else
{
    return(100);
}
like image 223
Jean Avatar asked Oct 27 '25 10:10

Jean


1 Answers

The best way is to wrap callee.pl in a 'sub {}' then require then script and call it. You can then treat the sub as a normal procedure.

File caller.pl

require("callee.pl");
printf("%d", callee());

File callee.pl

sub callee {
    if(<Went good>)
    {
        return(1);
    }
    else
    {
        return(100);
    }
}

1;
like image 51
user1937198 Avatar answered Oct 29 '25 05:10

user1937198