$ cat add.pl
sub MAIN($x, $y) { say $x + $y }
$ perl6 add.pl 3 4 7 $ perl6 add.pl too many arguments Usage: add.pl xy
$ cat add2.pl
sub MAIN($x, $y) { say $x + $y } sub USAGE() { say ": add.pl <num1> <num2>"; }
$ perl6 add2.pl too many arguments : add.pl <num1> <num2>
$ cat calc
#!/usr/bin/env perl6 multi MAIN('add', $x, $y) { say $x + $y } multi MAIN('div', $x, $y) { say $x / $y } multi MAIN('mult', $x, $y) { say $x * $y }
$ ./calc add 3 5 8 $ ./calc mult 3 5 15 $ ./calc Usage: ./calc add xy or ./calc div xy or ./calc mult xy
$ cat copy.pl
sub MAIN($source, $target, Bool :$verbose) { say " '$source' '$target'" if $verbose; run "cp $source $target"; }
$ perl6 copy.pl calc calc2 $ perl6 copy.pl --verbose calc calc2 'calc' to 'calc2'
$ cat do-nothing.pl
sub MAIN(:$how = '') { say " , $how"; }
$ perl6 do-nothing.pl , $ perl6 do-nothing.pl --how= , $ perl6 do-nothing.pl what? Usage: do-nothing.pl [--how=value-of-how]
Source: https://habr.com/ru/post/252451/
All Articles