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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With