S
Slickuser
I am trying to use Getopt::Long to get user input arguments.
If user input game.pl start mode:easy it will go to the start function
with mode:easy for options.
I'm not sure how to start it. Can you guys give me some hints. I have
some code below.
use strict;
use warnings;
use Getopt::Long;
&main;
sub main
{
my (@CMDS);
my $subcmds =
{
#game start -mode:easy
"start" =>
{
'sub' => \&subcmd_start,
'getopt' => ["-mode|m=s"],
},
";" =>
{
'sub' => \&subcmd_no_func,
}
};
foreach my $arg_func (@ARGV)
{
if (exists $subcmds->{$arg_func})
{
push(@CMDS, [$arg_func]);
next;
}
#else
#{
# print "AAAAAAA \n";
#}
}
foreach my $cmd (@CMDS)
{
#&exe_cmd($subcmds, $cmd->[0], $cmd->[1]);
}
return 1;
}
sub exe_cmd
{
}
sub subcmd_start
{
print "Starting... \n";
}
sub subcmd_no_func
{
print "No sub function... \n";
}
game.pl start mode:easy
game.pl stop
game.pl start mode:hard
game.pl exit
If user input game.pl start mode:easy it will go to the start function
with mode:easy for options.
I'm not sure how to start it. Can you guys give me some hints. I have
some code below.
use strict;
use warnings;
use Getopt::Long;
&main;
sub main
{
my (@CMDS);
my $subcmds =
{
#game start -mode:easy
"start" =>
{
'sub' => \&subcmd_start,
'getopt' => ["-mode|m=s"],
},
";" =>
{
'sub' => \&subcmd_no_func,
}
};
foreach my $arg_func (@ARGV)
{
if (exists $subcmds->{$arg_func})
{
push(@CMDS, [$arg_func]);
next;
}
#else
#{
# print "AAAAAAA \n";
#}
}
foreach my $cmd (@CMDS)
{
#&exe_cmd($subcmds, $cmd->[0], $cmd->[1]);
}
return 1;
}
sub exe_cmd
{
}
sub subcmd_start
{
print "Starting... \n";
}
sub subcmd_no_func
{
print "No sub function... \n";
}