in reply to sorting and other problems in hash

Did nobody notice that you can easily return the last X elements from an array by using a negative index?

Get the last 10 elements of the array:

@array = qw /1 2 3 4 5 6 7 8 9 10 11 12 13 14 15/; print join ' ', @array[-10 .. -1];
No need to get the length of the array with $#array, or reverse the array, ...

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Replies are listed 'Best First'.
Re^2: sorting and other problems in hash
by oko1 (Deacon) on Dec 31, 2008 at 15:34 UTC

    That was my original approach in returning the 'right' side. I found the approach I ended up taking a bit more readable and intuitive.


    --
    "Language shapes the way we think, and determines what we can think about."
    -- B. L. Whorf