Hi All,

I am having problem with array and Hash data structure. Example is show
below:

#CODE 1
my @list;
my %this;
$this{x} = 1;
$this{y} = 2;
$this{z} = 3;
$this{Z} = 4;
push @list, %this;

My intention above is to have variable @list as an array of hash, ie:
$list[0]{x}
$list[0]{y}
$list[0]{z}
$list[0]{Z}
or
%{$list[0]}

The last line does not work according to what I want it to do.
And instead, @list now contains:
$list[0] = 'x';
$list[1] = 1;
$list[2] = 'y';
$list[3] = '2';
.
.
.

I have resorted to:
@list[ scalar @list ] = %this;
which I find not so "elegant"...
What is the "correct" way of writing it anyways?

Secondly, is there a way to not use the has variable %this above?
ie, something like
push @list, {x=>1,y=>2,z=>3,Z=>4};
How should I write it "correctly"?

And lastly, as I try to pop it out:
%this = pop @list;
printf "%d %d %d %d\n", $this{x}, $this{y}, $this{z}, $this{Z};
it wont work. I am getting zeroes/blank on the hashes.
Why? How should I write it "correctly" again?


Thanks
Dan
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to