2

I have a script which takes 3 input variables from CLI and insert it to 3 variables respectively:

GetOptions("old_path=s" => \$old_path,
       "var=s"      => \$var,
       "new_path=s" => \$new_path,
       "log_path=s" => \$log_path)
or die ("Error in input variables\n");

Is there a way in which I can add a subroutine or any other GetOptions parameter which explains how to give the input variables?

toolic
  • 57,801
  • 17
  • 75
  • 117
deep
  • 686
  • 4
  • 17
  • 33

3 Answers3

6

The standard way in Perl is to use Pod::Usage as recommended in Getopt::Long. A complete example is shown in Documentation and help texts

toolic
  • 57,801
  • 17
  • 75
  • 117
3

It sounds like you're looking for Getopt::Long::Descriptive.

cjm
  • 61,471
  • 9
  • 126
  • 175
2

Try this, we can define HelpMessage subroutine with print statements what we want to show for command help,

    GetOptions("old_path=s" => \$old_path,
               "var=s"      => \$var,
               "new_path=s" => \$new_path,
               "log_path=s" => \$log_path,
                "help" => sub { HelpMessage() })
                 or die ("Error in input variables\n");
mpr4ul
  • 99
  • 1
  • Thank you for the input. But some correction in the above line: "help" => sub { HelpMessage() } will be "help" => \&Helpmessage.. – deep Jun 25 '13 at 23:11