I quickly wrote some sample code below that I hope would be more helpful to set your perl programming on the right track :-D
#!/usr/bin/perl use Getopt::Long; use Pod::Usage; # Recomend to use Pod::Usage along with Getopt::Long use strict; # Parse command line arguments and assign corresponding variables GetOptions ( 'f|fruit=s' => \( my $fruit = undef ), 'a|action=s' => \( my $action = undef ), 'g|greet' => \( my $greet = undef ), ); unless ( defined $action && defined $fruit ) { pod2usage( -exitval => 1, -output => \*STDERR ); } # do greeting print "Hello there!\n" if ($greet); # multiple fruit possible my @fruit = split /,/, $fruit; foreach (@fruit) { print "I will $action $_.\n"; # etc... } exit(0); __END__ =pod =head1 NAME fruit.pl =head1 SYNOPSIS fruit.pl [options] =head1 ARGUMENTS The -f and -a options are mandatory. The -g option is optional. =over 4 =item B<-f|--fruit [name]> Specify the fruit, multiple fruits possible, separate by comma =item B<-a|--action [name]> Specify the action to perform on fruit. =item B<-g|--greet> Print the greeting. =back =cut
Then you can run the program with command-line options:
perl ./fruit.pl -f apple,orange -a eat -g perl ./fruit.pl --fruit banana -action sell ...

In reply to Re: Calling options via Sub Routines by Roger
in thread Calling options via Sub Routines by sunadmn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.