Re: Illegal octal digit '9' problem??

2003-09-02 Thread Carl Jolley
On Tue, 2 Sep 2003, steve silvers wrote:

 With the below snippet, the numbers 8 and 9 work great, but 08 and
 09 give the error Illegal octal digit '9' or '8'. I read that these are
 two numbers that will have this problem! How do I get around this problem?


Ohh, don't use leading zeros on decimal numbers. Or read them (or force
then) to be strings. You can easily strip leading 0's from a string.
Lots of numbers may have this 'problem'. A leading 0 on a number indicates
that it is an octal number. All valid digits of an octal number range from
0..7. Just be glad you didn't try to use 010 as a decimal number. You
would have probably gotten really frustrated when you suddenly found the
value 8 amoung your data.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 


___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Illegal octal digit '9' problem??

2003-09-02 Thread Carl Jolley
On Tue, 2 Sep 2003, Keith C. Ivey wrote:

 steve silvers [EMAIL PROTECTED] wrote:

  use strict;
  my @numbers = (4,09,15);  # 09 will error, 9 won't error
  my @numbers2 = (2,4,11);
  my (%hash_lookup,%hash_lookup2);
  @[EMAIL PROTECTED] = ('Y') x @numbers;

 If you had 07 it wouldn't give an error, but it still wouldn't
 work unless '7' (not '07') is one of your hash keys, because
 07 would be converted to 7.  Hash keys are strings, and if you
 convert a number to a string it has no leading 0s.

 Numbers that start with 0 in Perl are interpreted as octal.
 Try this:

print 010;

 It prints '8'.  That's why 09 is an illegal number, since 9 is
 not an octal digit.

 If you want to use something as a string (as a hash key), then
 it's better to set it to be a string rather than a number in
 the first place, so no unexpected conversions happen.  You can
 do this:

 my @numbers = ('4', '09', '15');

 or, equivalently,

 my @numbers = qw( 4 09 15 );



Of course then '19' lt '9' so the numeric sort wouldn't work very well.
The best bet it to not use leading zeros or quoted strings but use sprintf
on the decimal values to generate the string value (with leading zeros)
for use as the hash keys and, of course on any value used to index a
hash key/value.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs