Sharan Basappa wrote:
>
> I was wondering if there is a quick way to remove an arbitrary element
> from an array.
> I have an array which stores _ delimited strings a_b_c_1). The last
> string stores the rank of the string.
> I have to remove a string from array that has the lowest number.
>
> e.g. a_b_c_1, a_b_c_2. In this case, a_b_c_2 should be removed. The
> strings are not arranged in any
> specific order in the array.
I'm hoping you've made a mistake, because if I understand you correctly then out
of ('a_b_c_1', 'a_b_c_2') the first should be removed because 1 is less than
two.
If I'm right then the program below should be useful.
HTH,
Rob
use strict;
use warnings;
my @data = qw/
a_b_c_99
a_b_c_6
a_b_c_1
a_b_c_2
a_b_c_22
/;
my ($idx, $min_seq);
foreach (0 .. $#data) {
my ($seq) = $data[$_] =~ /(\d+)$/;
next if defined $idx and $seq > $min_seq;
($idx, $min_seq) = ($_, $seq);
}
splice @data, $idx, 1;
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/