kranthi has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, I am using Term::ShellUI. While defining commands how to get the arguments that we passed to the command in the ShellUI as $ARGV doesnt work.
I have written the code for the same as mentioned below:
use Term::ShellUI; my $term = new Term::ShellUI( commands => { "exit" => { desc => "Quit this program", maxargs => 0, method => sub { shift->exit_requested(1); }, }, "help" => { desc => "This is a help file",maxargs => 3, method=> sub { my $self = shift; my $parms = shift; my $args = shift; my $args1 = shift; my $args2 = shift; print "\n $self "; print "\nThe first Arg is : $args\n"; print "\nThe secnd Arg is : $args1\n"; print "\nThe Third Arg is : $args2\n"; +}}, }, ); $term -> prompt("SAS>"); $term->run();
Is there any alternate way to get the three arguments directly without declaring the variables?

Replies are listed 'Best First'.
Re: How to retrieve arguments of command using Term::ShellUI
by pc88mxer (Vicar) on Jun 05, 2008 at 14:59 UTC
    If you want to use (or need to use) the syntax $ARGV[0], $ARGV[1], etc. to access the arguments, you can do this:
    method => sub { my ($self, @ARGV) = @_; print "The first argument is $ARGV[0]\n"; print "The second argument is $ARGV[1]\n"; ... }
    Otherwise, you can access the arguments directly from the @_ array variable:
    method => sub { print "I am $_[0]\n"; # print self print "The first argument is $_[1]\n"; print "The second argument is $_[2]\n"; ... }