Or similar to java's main() method? In other words a method that executes first, with the possibility of reading one or more parameters from the terminal.
Yes, and it's called MAIN and it has autoparsing for terminal parameters. Futhermore, it can even be a multi sub (supporting different signatures), have defaults, mark as required and do type validation, e.g.:
#|(optional description for USAGE message)
sub MAIN( Int :$length = 24,
:file($data) where { .IO.f // die "file not found in $*CWD" } = 'file.dat',
Bool :v(:$verbose) #`( -verbose, --verbose, -v or --v ) )
{
say $length if $length.defined;
say $data if $data.defined;
say 'Verbosity ', ($verbose ?? 'on' !! 'off');
exit 1;
}
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