in reply to Sort array according to a value in each element?

Although the sort function is un-glamorous and not very fast, there are times when it is adequate for the task at hand:

use strict; use warnings; my @array = ( 'Item1 - 2 foo, 2 bar', 'Item2 - 16 foo, 8 bar', 'Item3 - 0 foo, 1 bar', 'Item4 - 1 foo, 3 bar', 'Item5 - 4 foo, 12 bar', 'Item6 - 1 foo, 2 bar', ); @array = sort {get_bar($b) <=> get_bar($a)} @array; print "$_\n" for @array; sub get_bar { my ($line) = @_; my ($bar) = $line =~ /, (\d+) bar/; return $bar; }

There is no doubt that one of the transform methods would be much faster, though.

Hanlon's Razor - "Never attribute to malice that which can be adequately explained by stupidity"