Sharan Basappa wrote: > On Sun, Dec 7, 2008 at 2:01 AM, Rob Dixon <rob.di...@gmx.com> wrote: >> >> 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. >> >> >> >> 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; >> > > I have a question on this. I realized that I also need to save the element > that I am removing from the array. Would this code work (should remove the > element and save it in the variable) > > $removed_element = splice @data, $idx, 1
Exactly right. Yes. Rob -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/