Hello Perl Monks,
	I'm sure one you see what I am doing you may be like "What in the BLEEP, are or doing or thinking".
	Well, this is why I am reaching out to the Monks, as i believe there has to be a better way to do this.
	
	I am trying to locate all the element in the @ARGV that were passed via command line and ONLY delete some of them.
	in the example, I want to delete --config and --enter
	
	Now this is only a snippet of the code
	
	The results I get are now expected, but there has to be a much simpler way
> splice_tst.pl --debug --config --enter --config --config --enter +--help
use strict; Splice_Array("--config"); Splice_Array("--enter"); sub Splice_Array { print "Before Array Splicing: \n"; print "\t" . join(',', @ARGV), "\n"; my $value=shift; print "Splicing Value: $value\n"; my @matches = grep { $ARGV[$_] eq $value} 0..$#ARGV; # Just to Cou +nt the number of times the variable was identified print "$value is located at index(s): " . join(',', @matches), "\n +"; for my $match (@matches) { # just used for a Max loop count my @index = grep { $ARGV[$_] eq $value} 0..$#ARGV; print "Index:$index[0]\n"; splice @ARGV, $index[0] ,1; } print "After Array Splicing: \n"; print "\t" . join(',', @ARGV), "\n\n\n"; }
Output: C:\Temp>splice_tst.pl --debug --config --enter --config --config --ent +er --help Before Array Splicing: --debug,--config,--enter,--config,--config,--enter,--help Splicing Value: --config --config is located at index(s): 1,3,4 Index:1 Index:2 Index:2 After Array Splicing: --debug,--enter,--enter,--help Before Array Splicing: --debug,--enter,--enter,--help Splicing Value: --enter --enter is located at index(s): 1,2 Index:1 Index:1 After Array Splicing: --debug,--help C:\Temp>

In reply to 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.