Most importantly don't use empty prototypes () and use warnings
Anyway this works for me and avoids printing undefined values.
OUTPUT:use strict; use warnings; use Getopt::Long; GetOptions( 'demo' => \&demo, 'test' => \&test ) or die("Error in command line arguments\n"); sub demo { my ( $arg0, $arg1, $arg2, $arg3, $arg4, $arg5 ) = @_ ; warn "Number of args: ", scalar @_; die "expected 2 args" if @_ != 2; warn join ",",@_; } sub test { die "expected 2 args" if @_ != 2; warn join ",",@_; demo("hello", "world"); }
test,1 at d:/tmp/pm/getopt_long.pl line 23, <DATA> line 26. Number of args: 2 at d:/tmp/pm/getopt_long.pl line 16, <DATA> line 26. hello,world at d:/tmp/pm/getopt_long.pl line 18, <DATA> line 26.
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
In reply to Re: Passing Parameters to subroutine
by LanX
in thread Passing Parameters to subroutine
by g_speran
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |