Sharan Basappa wrote:
Hi,
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.
Regards
Sharan,
If I am understanding your problem correctly you have an array of
strings and at the last character of each string is the rank ? In order
to determine which string you want to remove you will have to sort by
that strings value. However you will most likely want to store this
data in a different manner.
I would need more information on the set of data to give a good solution
for a data structure. One way to handle this is in a hash if none of
the values are going to be repeated.
my %hash = ( 1 => 'a_b_c',
2 => 'second_a_b_c',
...);
And so on. Then you can simply sort by the hash's key values and remove
the last one in the list (depending on which way you sort).
Then if you needed all of that data back into the original array format
you could dump this hash back into the array (minus the one you removed
of course).
I hope this helps, provided I understood the problem correctly. If not
let me know and I'll try to help further.
Terry Grant
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/