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