> 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 Count 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 --enter --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>