1

How would I go about sorting the following arrays in the following by the value in TIME?

$VAR1 = [
          {
            'TIME' => '45',
            'PLAYER' => '',
            'TYPE' => '6'
          },
          {
            'INFO' => 'Dissent',
            'TEAMFLAG' => '1',
            'PLID' => '8570',
            'TIME' => '85',
            'PLAYER' => 'Player1',
            'TYPE' => '4'
          },
          {
            'TEAMFLAG' => '1',
            'PLID' => '8570',
            'TIME' => '35',
            'PLAYER' => 'Player1',
            'TYPE' => '1'
          },
          {
            'TEAMFLAG' => '0',
            'PLID' => '145399',
            'TIME' => '60',
            'PLAYER' => 'Player3',
            'TYPE' => '1'
          },
          {
            'TEAMFLAG' => '0',
            'PLID' => '145248',
            'TIME' => '12',
            'PLAYER' => 'Player1',
            'TYPE' => '1'
          },
          {
            'TIME' => '0',
            'PLAYER' => '',
            'TYPE' => '10'
          }
]

The above is a datadump of $data->{EVENTS}->{EVENT} which I need sorting, so have tried the following but it doesn't sort:

my @sorted =  sort { $b->{TIME} <=> $a->{TIME} } $data->{EVENTS}->{EVENT};

1 Answer 1

1

Hash and array elements are scalars. In this case, $data->{EVENTS}->{EVENT} is more speceifically a reference to an array. You want @{ $data->{EVENTS}->{EVENT} }.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.