in reply to Re: Printing a Hash Slice problem
in thread Printing a Hash Slice problem

Dear Taumarill,

Thanks for answering. Just a question regarding your code above:
my $mc = (sort {$$HoA{$a}[0] <=> $$HoA{$b}[0]} keys %$HoA)[-1];
1. What does '-1' means here?
2. Why '=' sign? Basically what does the statement above means?
How does it work?

Regards,
Edward

Replies are listed 'Best First'.
Re^3: Printing a Hash Slice problem
by jhourcle (Prior) on Mar 03, 2005 at 01:18 UTC

    [-1] is a negative array index, which lets you count from the other end of an array. $array[-1] is the same as [reverse @array]->[0] or $array[$#array]

    <=> is a comparison operator for numbers, similar to cmp for strings. (see perlop or the sort documentation)