Using Getopt::EvaP to parse command-line arguments

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • munkyeetr
    New Member
    • May 2007
    • 3

    Using Getopt::EvaP to parse command-line arguments

    I'm new to PERL, and am trying to use the Getopt::EvaP module to parse my command-line arguments, but I am a little lost as to how to make this work.

    So far I have downloaded and installed the module, and added the following to my script:

    [CODE=perl]use Getopt::EvaP;[/CODE]

    Now, I'm not sure where I add the PDT syntax; does this go in my script, or is it an external file? So there's PDT, MM, and OPT that I need to specify to make this work.

    Could someone please post a very basic working example of using this module, so that I can get a handle on how I can make it work in my script?

    Any help would be very appreciated.
  • miller
    Recognized Expert Top Contributor
    • Oct 2006
    • 1086

    #2
    The only advice that I have to give is to not use Getopt::EvaP. The most standard module that I know to use is Getopt::Long. The other module hasn't been updated since 1999.

    cpan Getopt::Long

    There are plenty of examples and documentation provided in that module.

    - Miller

    Comment

    • munkyeetr
      New Member
      • May 2007
      • 3

      #3
      Thank you. I'll try with that when I get home.

      Comment

      • numberwhun
        Recognized Expert Moderator Specialist
        • May 2007
        • 3467

        #4
        Also, in the spirit of TMTOWTDI:

        Keep in mind that you command line arguments are automatically plugged into the special array @ARGV.

        So, if you are just wanting someone to supply a file name, then you can get that file name into a variable by using:

        $varName = "@ARGV[0]";

        In addition, you can check to see if @ARGV has the required number of elements. Lets say that you have a requirement that 4 parameters must be specified to the script, then you could use the following to check that:

        if ($#ARGV != 4)
        {
        print usage statement;
        }

        The $#ARGV contains the number of elements in @ARGV. After than, you could test each argument for what might be expected or just move on to the next step, its up to you.

        Hope this helps.

        Regards,

        jlk

        Comment

        • KevinADC
          Recognized Expert Specialist
          • Jan 2007
          • 4092

          #5
          $#ARGV would be the index number of the last element of @ARGV, which is one less than the length of the array. So for four arguments:

          Code:
          if ($#ARGV != 3) {
              error message
          }

          Comment

          • numberwhun
            Recognized Expert Moderator Specialist
            • May 2007
            • 3467

            #6
            Originally posted by KevinADC
            $#ARGV would be the index number of the last element of @ARGV, which is one less than the length of the array. So for four arguments:

            Code:
            if ($#ARGV != 3) {
                error message
            }

            DOH!!! You are correct. I swear I have to start running things under your scanner to see if I mis-spoke before hitting "Submit Reply". :-)

            jlk

            Comment

            • munkyeetr
              New Member
              • May 2007
              • 3

              #7
              Thank you, everyone, for your replies...

              I changed to Getopt::Long and all is rosey again. Good documentation and excellent results. It's a handy module.

              Comment

              • miller
                Recognized Expert Top Contributor
                • Oct 2006
                • 1086

                #8
                Excellent.

                Glad that we could help.

                - Miller

                Comment

                Working...