|
Posted by bugbear on March 4, 2008, 8:29 am
Please log in for more thread options Tomasz Chmielewski wrote:
> Peter Makholm schrieb:
>>
>>> I would use 'split', but "some-name" is not static, and can be
>>> "some-other-name" or just "name" a task later.
>>>
>>> For the same reason, using 'substr' won't work.
>>>
>>> Unless I write a subroutine to it.
>>
>> Yes, you have to tell us (and perl) how to extract the number you want
>> to sort the lines after.
>>
>> And the you sorting is trivial:
>>
>> @sorted = sort { extract($a) <=> extract($b) } @unsorted
>
> I guess I'll just use something like, it does not have to be
> super-efficient:
>
> sub extract() {
> my $name = shift;
> my @columns = split /-/, $name;
> my $last_column = $columns[$#columns];
> }
or specifically go for trailing digits?
sub extract {
my $name = shift;
$name =~ m/(\d+)$/;
return $1;
}
|