On Fri, 26 Nov 2004 20:41:01 -0800, $Bill Luebkert wrote:
>�peace under the tree wrote:
>>�I code this program but It don' t run, I don't know what the
>>�problem with it, Can anyone help? Thank you!
>>
>�Try (note the quoted numbers in hash keys) :

To follow up on what Bill said and better understand why your code didn't work 
as you expected, try this program:

#!/Perl/bin/perl
use strict;
use warnings;
use Data::Dumper;

my %person=( name =>   { 0001=>'chao sophal',
                         0003=>'lee lyekuan',
                         0002=>'theavylong',
                         0004=>'surgrapany',
                         00056=>'SZE PENG'
                       },
             age   =>  { 0001=>'22',
                         0003=>'20',
                         0002=>'22',
                         0004=>'24',
                         00056=>'26'
                       },
             school => { 0001=>'Unversity Science Malaysia',
                         0003=>'Northing University',
                         0002=>'Stamford College',
                         0004=>'Summani Informaiton Technology, India',
                         00056=>'Norting University'
                       }
            );
print Dumper \%person;
-------------------------------------------------
The printout looks like this:

$VAR1 = {
          'name' => {
                      '4' => 'surgrapany',
                      '1' => 'chao sophal',
                      '46' => 'SZE PENG',
                      '3' => 'lee lyekuan',
                      '2' => 'theavylong'
                    },
          'school' => {
                        '4' => 'Summani Informaiton Technology, India',
                        '1' => 'Unversity Science Malaysia',
                        '46' => 'Norting University',
                        '3' => 'Northing University',
                        '2' => 'Stamford College'
                      },
          'age' => {
                     '4' => '24',
                     '1' => '22',
                     '46' => '26',
                     '3' => '20',
                     '2' => '22'
                   }
        };
--------------------------------------------

As you can see, perl simplified your unquoted numerical strings by dropping the 
leading zeros *before* stringifying them to use as hash keys. Quoting them 
explicitly solves the problem.

I admit I'm a little surprised by this behavior. The auto-quoting function of 
=> doesn't work quite as literally as I thought.

HTH,
David


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

Reply via email to