Как-то так?

#!/usr/bin/perl
use strict;
use warnings;

use Data::Dumper;

my $sort_index2 = 0;

my @a = (
          {
             name        => 'a',
             sort        => 0,
             sort_index2 => ++$sort_index2,
          },
          {
             name        => 'b',
             sort        => 4,
             sort_index2 => ++$sort_index2,
          },
          {
             name        => 'c',
             sort        => 10,
             sort_index2 => ++$sort_index2,
          },
);

push @a,
  {
    name        => 'd',
    sort        => 0,
    sort_index2 => ++$sort_index2,
  };

print Dumper \...@a;
@a = sort my_sort @a;
print Dumper \...@a;


sub my_sort
{
    my $answer;
    if ( $a->{sort} > $b->{sort} )
    {
        $answer = 1;
    }
    elsif ( $a->{sort} < $b->{sort} )
    {
        $answer = -1;
    }
    else
    {
        $answer = 0;
    }

    if ( $answer == 0 )
    {
        if ( $a->{sort_index2} > $b->{sort_index2} )
        {
            $answer = -1;
        }
        else
        {
            $answer = 1;
        }
    }
return $answer;
}
--
Moscow.pm mailing list
[email protected] | http://moscow.pm.org

Ответить