Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Array of Hashes ?

Reply
Thread Tools

Array of Hashes ?

 
 
Tom
Guest
Posts: n/a
 
      11-17-2004
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:umper()

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

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'
]
]
];
---------------------------------------------------
 
Reply With Quote
 
 
 
 
Matija Papec
Guest
Posts: n/a
 
      11-17-2004
X-Ftn-To: Tom

http://www.velocityreviews.com/forums/(E-Mail Removed) (Tom) wrote:
>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:umper()
>
>I am pushing Hash1, Hash2 in to an Array
>I don't see => when 'm priting the Array using Data:umper()
>
>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?



--
Matija
 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      11-17-2004
(E-Mail Removed) (Tom) wrote in
news:(E-Mail Removed) m:

> 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:umper()
>
> 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:umper()


Have you read

perldoc perldsc

Sinan
 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      11-17-2004
"Tom" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) m...
> 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:umper()
>
> I am pushing Hash1, Hash2 in to an Array
> I don't see => when 'm priting the Array using Data:umper()


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

 
Reply With Quote
 
Thomas Kratz
Guest
Posts: n/a
 
      11-17-2004
Tom wrote:
> 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:umper()
>
> 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^.-
 
Reply With Quote
 
Peter Wyzl
Guest
Posts: n/a
 
      11-18-2004
"A. Sinan Unur" <(E-Mail Removed)> wrote in message
news:Xns95A47DA443544asu1cornelledu@132.236.56.8.. .
> (E-Mail Removed) (Tom) wrote in
> news:(E-Mail Removed) m:
>
>> 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:umper()
>>
>> 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:umper()

>
> 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?

--
Wyzelli
print "oh how nice\n";


 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      11-18-2004

Quoth "Peter Wyzl" <(E-Mail Removed)>:
> "A. Sinan Unur" <(E-Mail Removed)> wrote in message
> news:Xns95A47DA443544asu1cornelledu@132.236.56.8.. .
> > (E-Mail Removed) (Tom) wrote in
> > news:(E-Mail Removed) m:
> >
> >> 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:umper()
> >>
> >> 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:umper()

> >
> > 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?


Send a patch to p5p ((E-Mail Removed), or
nntp://nntp.perl.org/perl.perl5.porters).

Ben

--
"The Earth is degenerating these days. Bribery and corruption abound.
Children no longer mind their parents, every man wants to write a book,
and it is evident that the end of the world is fast approaching."
-Assyrian stone tablet, c.2800 BC (E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Array of Hashes in an array of hashes - Complicated! Matt Brooks Ruby 16 09-16-2009 05:53 PM
How to make an array of hashes to a single array with all thevalues of these hashes ? kazaam Ruby 12 09-13-2007 01:30 PM
using hashes as keys in hashes Steven Arnold Ruby 3 11-23-2005 03:25 PM
Hash of hashes, of hashes, of arrays of hashes Tim O'Donovan Perl Misc 5 10-28-2005 05:59 AM
Hashes of Hashes via subs Ben Holness Perl 8 10-08-2003 06:57 AM



Advertisments