Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
In the node (tye)Re: Base36 numbers: speed and golf tye had a line in his code:
@next{'0'..'9','A'..'Z'}= ('1'..'0','A'..'Z','0');
where he sets up a mapping of each of the base36 digits and their successor digits. What caught my eye was the part '1'..'0' on the RHS. At first I thought it might be a typo and tye really meant to type '9' instead of '0', but I immediately scolded myself for doubting tye (after all he has provided test data at the end of his program, so he surely must have tested it before posting, unlike me).

So, I looked in perlop, which says about the range (..) operator:

In list context, it returns an array of values counting (up by ones) from the left value to the right value. If the left value is greater than the right value then it returns the empty array.
Following this, '1'..'0' should result in an empty array. But that is not what I have seen.
>> perl -MO=Deparse -le '@x = (0 .. 9)' @x = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9); >> perl -MO=Deparse -le '@x = (1 .. 0)' @x = (); >> perl -MO=Deparse -le '@x = ("0" .. "9")' @x = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'); >> perl -MO=Deparse -le '@x = ("1" .. "0")' @x = ('1', '2', '3', '4', '5', '6', '7', '8', '9'); >> perl -le 'print "1" > "0" ? "yes" : "no"' yes
It works as expected for the integer list case (returns the empty array), but in the other case of list of number strings, perl gives me a non-empty list even though, "1" > "0" is true. And, to top that, the resulting list stops short at '9'.

What am I missing?

/prakash


In reply to Range operator weirdness? by PrakashK

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others taking refuge in the Monastery: (2)
    As of 2014-07-12 23:43 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      When choosing user names for websites, I prefer to use:








      Results (242 votes), past polls