in reply to Passing Parameters to subroutine
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Passing Parameters to subroutine
by g_speran (Scribe) on Mar 18, 2022 at 02:14 UTC | |
by Marshall (Canon) on Mar 21, 2022 at 10:41 UTC | |
|
Re^2: Passing Parameters to subroutine
by g_speran (Scribe) on Mar 18, 2022 at 00:58 UTC | |
by Fletch (Bishop) on Mar 18, 2022 at 01:23 UTC | |
by LanX (Saint) on Mar 18, 2022 at 10:03 UTC |