PrakashK has asked for the wisdom of the Perl Monks concerning the following question:
In the node (tye)Re: Base36 numbers: speed and golf tye had a line in his code:
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).@next{'0'..'9','A'..'Z'}= ('1'..'0','A'..'Z','0');
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.
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'.>> 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
What am I missing?
/prakash
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Range operator weirdness?
by xtype (Deacon) on Feb 28, 2002 at 16:56 UTC | |
Re: Range operator weirdness?
by Ido (Hermit) on Feb 28, 2002 at 15:38 UTC | |
by PrakashK (Pilgrim) on Feb 28, 2002 at 15:51 UTC | |
Re: Range operator weirdness?
by dragonchild (Archbishop) on Feb 28, 2002 at 15:48 UTC | |
by Sweeper (Pilgrim) on Feb 28, 2002 at 21:03 UTC | |
Re: Range operator weirdness?
by petral (Curate) on Feb 28, 2002 at 16:27 UTC | |
by tye (Sage) on Mar 01, 2002 at 06:30 UTC | |
by grummerX (Pilgrim) on Mar 01, 2002 at 10:45 UTC | |
by tye (Sage) on Mar 01, 2002 at 15:55 UTC | |
by PrakashK (Pilgrim) on Mar 01, 2002 at 14:42 UTC | |
Re: Range operator weirdness?
by lzcd (Pilgrim) on Feb 28, 2002 at 21:23 UTC |
Back to
Seekers of Perl Wisdom