background preloader

Perl

Facebook Twitter

Day 2 – Interacting with the command line with MAIN subs « Perl 6 Advent Calendar. By Moritz In Unix environment, many scripts take arguments and options from the command line.

Day 2 – Interacting with the command line with MAIN subs « Perl 6 Advent Calendar

With Perl 6 it’s very easy to accept those: $ 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 x y By just writing a subroutine called MAIN with a signature, you automatically get a command line parser, binding from the command line arguments into the signature variables $x and $y, and a usage message if the command line arguments don’t fit. The usage message is customizable by adding another sub called USAGE: Perl 6 Advent Calendar. Advent Calendar.

Dancer Advent Calendar The PerlDancer Advent Calendar is a community-driven project that aims to showcase the Dancer Perl web framework.

Advent Calendar

Each day of December until Christmas, one article about Dancer. Stay tuned for new moves!