Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3796568
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:15:23+00:00 2026-05-19T13:15:23+00:00

I am wanting to integrate the use of ARGV into my script. After messing

  • 0

I am wanting to integrate the use of ARGV into my script. After messing with an example of a simple usage I found on Stack Overflow, I was able to make the script “enforce” the use of single command args. The thing that I am wanting to now is to allow for multiple flags instead of just one. The catch is the flags need to be enforced in a specific order if there are multiple used.

Here is the code I have come up with for doing single args and enforcing it.

#!/usr/bin/perl
use strict;
use warnings;

system ("clear");
print "Solignis's Discovery Script v0.6 for ESX\\ESX(i) 4.0+\n\n";

my $numargs = $#ARGV + 1;

if ($#ARGV < 0) {
    help_menu();
}

foreach my $argval (0 .. $#ARGV) {
    if (($#ARGV == 0) && ($ARGV[0] eq '-b')) {
        print "Backup\n";
    } elsif (($#ARGV == 0) && ($ARGV[0] eq '-d')) {
        print "Discovery\n";
    } elsif ((($#ARGV == 0) && ($ARGV[0] eq '-h') || ($#ARGV == 0) && ($ARGV[0] eq '-?'))) {
        help_menu();
    } elsif (($#ARGV == 0) && ($ARGV[0] eq '-s')) {
        print "Setup\n"
    }
}

if ($#ARGV >= 1) {
    print "Too many arguments, only one argument may be passed at a time!\n";
}

sub help_menu {
    print "Options:\n\n";
    print "\t-b\tRun Backup Backup\n";
    print "\t-d\tRun Discovery Script\n";
    print "\t-h\tShow Help Menu\n";
    print "\t-s\tRun Setup Script\n\n";
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T13:15:23+00:00Added an answer on May 19, 2026 at 1:15 pm

    Use the core Getopt::Long module and don’t worry about parsing arguments yourself.

    If you have multiple arguments, instead of doing whatever they say in the order they say, you just do something like the following pseudocode:

    if( option s is set ) {
      run setup stuff
    }
    if( option b is set ) {
      run backup stuff
    }
    

    There’s absolutely no reason why your script should allow arguments as -s -b and not -b -s. Your users will expect that if they supply -b -s that setup will be done first, then backup. Your script should be smart enough.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Wanting to integrate aspects of SharePoint into an existing website - rather than integrating
I have to integrate a Java applet into a simple asp.net 2.0 control. This
I'm wanting to integrate Twitter and Facebook into a game using Cocos2D. I just
I'm wanting to extract a zip file loaded with images into memory in some
I'm wanting to use a php variable as the destination email for Amazon SES
I am wanting to discover what possible standard .net exceptions can cause stack traces
I'm wanting to use Envers to audit a many-to-many relation with an embedded component
I heard a lot about apples new transit api. Im wanting to integrate this
I want to move various parts of my app into simple scripts, to allow
Wanting to give byobu a looksee as a screen 'update' of sorts. I start

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.