in reply to Re^3: beginner - ordering tuples
in thread beginner - ordering tuples

I've just noticed, why has it put some of the output in single quotes: (look at the first and last one). I did it with different data and the last 2 tuples had quotes around the second value.
$VAR1 = [ [ 1, '5' ], [ 7, 15 ], [ 7, 12 ], [ 7, 10 ], [ 12, '20' ] ];

Replies are listed 'Best First'.
Re^5: beginner - ordering tuples
by BrowserUk (Patriarch) on Nov 13, 2010 at 14:24 UTC
    why has it put some of the output in single quotes:

    The input array is initialised with strings. Left unmodified, all the values would be output in quotes.

    During the sort process, any values that are compared as numbers using <=>, will first be converted, internally, to their (binary) numeric representation.

    But as the first & last pairs in your example have unique first elements (1 & 12), there is never any need to compare their second elements, hence they are never converted to numeric representation, and so are output as strings.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
    +