Array of Hashes ?

T

Tom

Well, I am a beginner as far as perl is concerned.
Can some one point me that 'm doing is correct.
I have pasted below my hash and array using Data::Dumper()

I am pushing Hash1, Hash2 in to an Array
I don't see => when 'm priting the Array using Data::Dumper()

By looking at the dump can someone ascertain if I have formed an Array
of Hashes or not?



--------------------------------



Tom> Hash 1:
$VAR1 = {
'1' => [
'0'
],
'0' => [
'0'
],
'TestCase' => [
'PC_Battery'
]
};

Tom> Hash 2:
$VAR1 = {
'1' => [
'0'
],
'0' => [
'0'
],
'2' => [
'0'
],
'TestCase' => [
'PC_Something'
]
};

Tom> Array of Hashes: (?)
$VAR1 = [
[
'1',
[
'0'
],
'0',
[
'0'
],
'TestCase',
[
'PC_Battery'
]
],
[
'1',
[
'0'
],
'0',
[
'0'
],
'2',
[
'0'
],
'TestCase',
[
'PC_Something'
]
]
];
---------------------------------------------------
 
M

Matija Papec

X-Ftn-To: Tom

Well, I am a beginner as far as perl is concerned.
Can some one point me that 'm doing is correct.
I have pasted below my hash and array using Data::Dumper()

I am pushing Hash1, Hash2 in to an Array
I don't see => when 'm priting the Array using Data::Dumper()

By looking at the dump can someone ascertain if I have formed an Array
of Hashes or not?

No, you didn't. What do you want to accomplish?
 
A

A. Sinan Unur

(e-mail address removed) (Tom) wrote in
Well, I am a beginner as far as perl is concerned.
Can some one point me that 'm doing is correct.
I have pasted below my hash and array using Data::Dumper()

I am pushing Hash1, Hash2 in to an Array

comp.lang.perl.mindreadres is down the hall to your right.
I don't see => when 'm priting the Array using Data::Dumper()

Have you read

perldoc perldsc

Sinan
 
P

Paul Lalli

Tom said:
Well, I am a beginner as far as perl is concerned.
Can some one point me that 'm doing is correct.
I have pasted below my hash and array using Data::Dumper()

I am pushing Hash1, Hash2 in to an Array
I don't see => when 'm priting the Array using Data::Dumper()

I really don't understand what any of this means.
By looking at the dump can someone ascertain if I have formed an Array
of Hashes or not?

Afraid not. See below.
Tom> Hash 1:
$VAR1 = {
'1' => [
'0'
],
'0' => [
'0'
],
'TestCase' => [
'PC_Battery'
]
};


Here, $VAR1 is a reference to a hash with three key/value pairs. The
keys are '0', '1', and 'TestCase'. Each value of the hash in a
reference to an array that contains one element each.
Tom> Hash 2:
$VAR1 = {
'1' => [
'0'
],
'0' => [
'0'
],
'2' => [
'0'
],
'TestCase' => [
'PC_Something'
]
};

Same exact thing, but with an extra key/value pair in the hash.
Tom> Array of Hashes: (?)
$VAR1 = [
[
'1',
[
'0'
],
'0',
[
'0'
],
'TestCase',
[
'PC_Battery'
]
],


There is no hash in here anywhere. You have an array of array
references. The first element in the overall array is an array
reference. That array contains the values: 1, (a reference to an array
containing 0), 0, (a reference to another array containing 0),
'TestCase', and (a reference to an array containing 'PC_Battery')

At this point, it would be helpful to see your code so we can help you
see where you went wrong in creating an array where you thought you were
creating a hash.

Paul Lalli
 
T

Thomas Kratz

Tom said:
Well, I am a beginner as far as perl is concerned.
Can some one point me that 'm doing is correct.
I have pasted below my hash and array using Data::Dumper()

I am pushing Hash1, Hash2 in to an Array

No. The data you posted shows that you pushed two anonymous arrays
containing the flattened hashes into the array.

I assume you did:

push @Array, [%Hash1];
push @Array, [%Hash2];

Try to push *references* to Hash1 and Hash2 to the Array like so:

push @Array, \%Hash1;
push @Array, \%Hash2;

See perldoc perlreftut

Next time post real code.
And please have a look at the posting guidelines.

Thomas

--
$/=$,,$_=<DATA>,s,(.*),$1,see;__END__
s,^(.*\043),,mg,@_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
$_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
'%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e.r^.>l^..>k^.-
 
P

Peter Wyzl

A. Sinan Unur said:
(e-mail address removed) (Tom) wrote in


comp.lang.perl.mindreadres is down the hall to your right.


Have you read

perldoc perldsc

Actually, that reminds me. It's probably time that doc got updated. My
copy (Perl 5.8.3) was written in 1996 and makes assertions about inability
to write complex data representations to disk which have been well fixed by
Storable.

Who would handle that?
 
B

Ben Morrow

Quoth "Peter Wyzl said:
Actually, that reminds me. It's probably time that doc got updated. My
copy (Perl 5.8.3) was written in 1996 and makes assertions about inability
to write complex data representations to disk which have been well fixed by
Storable.

Who would handle that?

Send a patch to p5p ([email protected], or
nntp://nntp.perl.org/perl.perl5.porters).

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Dumper 4
Array of structs function pointer 10
Sorting hash of hashes 9
array of hashes 3
Parsing an Array of Hashes 3
array of hashes 1
Array accessing problem 2
2d array of hashes 3

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top