Well, first off, I would direct you to Getopt::Long which has just about every common option you could want for command line argument parsing. In particular, check out the option pass_through:

pass_through (default: disabled)

With "pass_through" anything that is unknown, ambiguous or supplied with an invalid option will not be flagged as an error. Instead the unknown option(s) will be passed to the catchall "<>" if present, otherwise through to @ARGV. This makes it possible to write wrapper scripts that process only part of the user supplied command line arguments, and pass the remaining options to some other program.

If "require_order" is enabled, options processing will terminate at the first unrecognized option, or non-option, whichever comes first and all remaining arguments are passed to @ARGV instead of the catchall "<>" if present. However, if "permute" is enabled instead, results can become confusing.

Note that the options terminator (default "--"), if present, will also be passed through in @ARGV.

If that can't solve the problem, my default fall-back approach would be to just write a plain old C-style loop:

for (my $i= 0; $i < @ARGV; $i++) { if ($ARGV[$i] eq '--config') { splice(@ARGV, $i, 1); $i-- } }
It isn't pretty or fancy, but it lets you make all the special cases you need, like consuming additional arguments, or skipping over arguments according to the particular rules of the commandline syntax for that program. A more elegant bit of code (if your needs are really simple) is to iterate backwards:
for (reverse 0..$#ARGV) { splice(@ARGV, $_, 1) if $ARGV[$_] eq '--config'; }
but that doesn't give you much opportunity to handle special cases.

In reply to Re: Locate emement in array and delete by NERDVANA
in thread Locate emement in array and delete by g_speran

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.