0

I am trying to sort an array, but the output is not as expected. My array has:

11873
11873
11873
14361
16857
15795
14361
14361
14361

After I sort with following code, I get same array:

@sort_start= (sort{my $b <=>my $g} @start);

I cannot understand why.

1 Answer 1

1

You should use $a instead of $g, and don't use my in the sort block. Refer to perldoc -f sort:

@sort_start= sort {$b <=> $a} @start;

You should use warnings. That would've shown you some messages.

If you want to sort in ascending order, swap $a and $b.

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.