Hello. I'm using defferent 5.6.0's for Win32. I wonder wheter following behaviour is intentional or not: d:\>perl -e "print 'b'..'c'" bc d:\>perl -e "print 'b'..'a'" bcdefghijklmnopqrstuvwxyz I expected empty list in latter case, like in perl -e "print 'bb'..'a'" <!ENTITY Vadim REALLIFE "Vadim V.Konovalov, St.Petersburg, Russia"> &Vadim;
![]() |
0 |
![]() |
On Wed, Sep 20, 2000 at 03:14:41PM +0400, Konovalov, Vadim wrote: > Hello. > > I'm using defferent 5.6.0's for Win32. > I wonder wheter following behaviour is intentional or not: > > d:\>perl -e "print 'b'..'c'" > bc > > d:\>perl -e "print 'b'..'a'" > bcdefghijklmnopqrstuvwxyz > > I expected empty list in latter case, like in > perl -e "print 'bb'..'a'" > If you're wondering whether the behavior of an operator is intentional, the first thing to do is read the documentation to see if the behavior is documented. perldoc perlop: The range operator (in list context) makes use of the magical auto-increment algorithm if the operands are strings. You can say @alphabet = ('A' .. 'Z'); to get all normal letters of the alphabet, or $hexdigit = (0 .. 9, 'a' .. 'f')[$num & 15]; to get a hexadecimal digit, or @z2 = ('01' .. '31'); print $z2[$mday]; to get dates with leading zeros. If the final value specified is not in the sequence that the magical increment would produce, the sequence goes until the next value would be longer than the final value specified. Starting from 'b', 'a' is not in the sequence produced by magical increment, so the sequence stops when it gets to 'aa', which is longer than 'b'. Ronald
![]() |
0 |
![]() |
> Starting from 'b', 'a' is not in the sequence produced by magical > increment, so the sequence stops when it gets to 'aa', which is > longer than 'b'. While it is true that 'aa' is longer 'b', what is relevant is that 'aa' is longer than 'a'. % perl -lwe 'print join " ","zo".."A"' % perl -lwe 'print join " ","zo".."AA"' zo zp zq zr zs zt zu zv zw zx zy zz % perl -lwe 'print join " ","zo".."AAA"' zo zp zq zr zs zt zu zv zw zx zy zz aaa aab aac aad aae aaf aag aah aai aaj aak aal aam aan aao aap aaq aar aas aat aau aav aaw aax aay aaz aba abb abc abd abe .... zzb zzc zzd zze zzf zzg zzh zzi zzj zzk zzl zzm zzn zzo zzp zzq zzr zzs zzt zzu zzv zzw zzx zzy zzz Robin -- Robin Barker | Email: Robin.Barker@npl.co.uk CMSC, Building 10, | Phone: +44 (0) 20 8943 7090 National Physical Laboratory, | Fax: +44 (0) 20 8977 7091 Teddington, Middlesex, UK. TW11 OLW | WWW: http://www.npl.co.uk
![]() |
0 |
![]() |
On Wed, Sep 20, 2000 at 09:29:38AM -0400, "Ronald J Kimball" wrote: > to get dates with leading zeros. If the final value specified is not > in the sequence that the magical increment would produce, the sequence > goes until the next value would be longer than the final value > specified. > Starting from 'b', 'a' is not in the sequence produced by magical > increment, so the sequence stops when it gets to 'aa', which is longer than > 'b'. Somebody can tell me I'm wrong, but I consider that behaviour relatively useless. Either an error, an empty list, or auto-decrement would seem to make more sense. mark -- markm@nortelnetworks.com/mark@mielke.cc/markm@ncf.ca __________________________ .. . _ ._ . . .__ . . ._. .__ . . . .__ | SIR Tools (7H12) |\/| |_| |_| |/ |_ |\/| | |_ | |/ |_ | Nortel Networks | | | | | \ | \ |__ . | | .|. |__ |__ | \ |__ | Ottawa, Ontario, Canada One ring to rule them all, one ring to find them, one ring to bring them all and in the darkness bind them... http://mark.mielke.cc/
![]() |
0 |
![]() |