Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I capture the returned value of a routine used in RUN-MAIN?

I want a script to run a subroutine exported from a module, with the exported sub to be run as MAIN in the script. The subroutine does all that I want, except that it returns the result instead of printing it.

RUN-MAIN seems to achieve most of what I'm aiming for, but I'm not sure how to grab the returned value of the routine.

Is there a way I can capture the output of the routine given to RUN-MAIN to be printed? Is RUN-MAIN the right approach for this sort of thing?

like image 888
Daniel Mita Avatar asked Nov 19 '19 18:11

Daniel Mita


1 Answers

You could use the function composition operator infix:<∘> or infix:<o>

sub foo ($name, Int $n=1) { 
    "Hello $name\n" xx $n 
}; 
RUN-MAIN &say o &foo, Nil; #or &foo Ro &say

but unfortunately, it is changing the signature

sub foo ($name, Int $n=1) { 
    "Hello $name\n" xx $n 
};

say &foo.signature;
say (&foo Ro &say).signature;

so default USAGE message does not work.

like image 118
wamba Avatar answered Sep 30 '22 17:09

wamba