g_speran has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use strict; use Getopt::Long; GetOptions ('demo' => \&demo, 'test' => \&Test) or die("Error in command line arguments\n"); sub demo () { die "Wrong number of args" if (scalar(@_) != 2); my $arg0 = $_[0]; my $arg1 = $_[1]; my $arg2 = $_[2]; my $arg3= $_[3]; my $arg4 = $_[4]; my $arg5 = $_[5]; print "$arg0, $arg1, $arg2, $arg3, $arg4, $arg5\n"; } sub Test () { # call the subroutine my $arg0 = $_[0]; my $arg1 = $_[1]; my $arg2 = $_[2]; my $arg3= $_[3]; my $arg4 = $_[4]; my $arg5 = $_[5]; print "$arg0, $arg1, $arg2, $arg3, $arg4, $arg5\n"; &demo("hello", "world"); } C:\temp>passparm.pl --demo demo, 1, , , , <== would expect nothing to print C:\temp>passparm.pl --test test, 1, , , , <== would expect nothing to print hello, world, , , , <== Expected C:\temp>passparm.pl --demo --test demo, 1, , , , <== would expect nothing to print test, 1, , , , <== would expect nothing to print hello, world, , , , <== Expected
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Passing Parameters to subroutine
by LanX (Saint) on Mar 18, 2022 at 00:24 UTC | |
by g_speran (Scribe) on Mar 18, 2022 at 02:14 UTC | |
by Marshall (Canon) on Mar 21, 2022 at 10:41 UTC | |
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 | |
|
Re: Passing Parameters to subroutine
by haukex (Archbishop) on Mar 18, 2022 at 05:41 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |