I have an array that looks like this:
array [0]: 6 8 array [1]: 12 9 6 array [2]: 33 32 5 array [3]: 8 6 I want to sort this array so that it looks like this :
array [0]: 6 8 array [1]: 6 9 12 array [2]: 5 32 33 array [3]: 6 8 < P> I know I can sort the array with the @newarray = sort {$ a cmp $ b} @array , but I need to sort the elements in each line. How can i What?
Believing that you have an array of strings, and all that you want is every string Sorting as if it was the sub-array of numbers (but left it the string?):
#! Strict / usr / bin / env perl; Use warnings; My @array = ('6 8', '126 ', '33 32 5', '8 6'); Removing my $ string (@array) {$ string = split_sort ($ string); } Sub split_sort {my $ string = shift @_; My @internal_nums = split '', $ string; @internal_nums = sort {$ a & lt; = & Gt; $ B} @inline_names; Join the return '', @inant_name; } Print "@ARA \ n";
Comments
Post a Comment