Perl hash of hashes anonymous array


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl hash of hashes anonymous array
# 1  
Old 09-15-2016
Perl hash of hashes anonymous array

Hello experts. I'm having problems with a snippet of code.
I was hoping to get help/advice to correct.
A file that this script parses has changed to the point where
I can no longer use a scalar, it looks as though I need to
create an array for a hash of hashes below.

The first output of Dumper is from the actual script, the desired output
is what I think I need to assign. The problem with the script now is the
hash gets overwritten with the next valid value, I need to display all the values.
This is why I think I need an anonymous array within the hash of hashes.
I'm having issues with using push on this array. I can't seem to figure out the
correct syntax for this. I'll probably need help in dereferencing it as well, because
frankly I'm getting burnt out on this one.

Thanks guys


Code:
foreach my $z (sort keys %team) {
    for $y (@{$team{$z}}) {
      $_raw{$z}{$lookupph{$y}}=$y;
    }
}
print Dumper \%_raw;



-- Output --

'account' => {
                      'name01' => 'phone1',
                      'name02' => 'phone1',
                      'name03' => 'phone1',
                      'name04' => 'phone1',
                      'name05' => 'phone1',
                      'name06' => 'phone1',
                      'name07' => 'phone1',

					  
					  
Disired output

'account' => {
                      'name01' => ['phone1', 'phone2']
                      'name02' => ['phone1', 'phone2']
                      'name03' => ['phone1', 'phone2']
                      'name04' => ['phone1', 'phone2']
                      'name05' => ['phone1', 'phone2']
                      'name06' => ['phone1', 'phone2']
                      'name07' => ['phone1', 'phone2']



Also, how would I dereference the desired array reference?

Thanks in advanced.
# 2  
Old 09-15-2016
Can you tell what your perl code is doing a brief synopsis would suffice and also what kind of variables are being used and for what as this would give us all a starting point...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare values of hashes of hash for n number of hash in perl without sorting.

Hi, I have an hashes of hash, where hash is dynamic, it can be n number of hash. i need to compare data_count values of all . my %result ( $abc => { 'data_count' => '10', 'ID' => 'ABC122', } $def => { 'data_count' => '20', 'ID' => 'defASe', ... (1 Reply)
Discussion started by: asak
1 Replies

2. Shell Programming and Scripting

Perl : array of hashes help

Hi, I have array of hashes and each key has array like below. @array1 = ( { 'url' => , 'bill' => }, { 'url' => , 'bill' => }, { 'url' => , ... (0 Replies)
Discussion started by: ragilla
0 Replies

3. Shell Programming and Scripting

perl: dereferencing a hash of hashes

Hi there, I am trying to dereference my hash of hashes but post dereferencing, it seems to lose its structure I am using Data::dumper to help me anaylise. This is the code im using to build the HoH, (data comes from a file). I have also performed a Dumper on the data structure before and after... (1 Reply)
Discussion started by: rethink
1 Replies

4. Shell Programming and Scripting

Regarding anonymous hash in PERL

Hi, I have doubt regarding the Anonymous hash. For creating a object we are generally using Anonymous hash. My Doubt is: Why we are only using Anonymous hash?? Instead of Anonymous hash can we use global hash variable and take its reference for creating an object using same bless function??... (0 Replies)
Discussion started by: jatanig
0 Replies

5. Shell Programming and Scripting

Need explanation on Anonymous hash in PERL!!

Hi, I have doubt regarding the Anonymous hash. For creating a object we are generally using Anonymous hash. My Doubt is: Why we are only using Anonymous hash?? Instead of Anonymous hash can we use global hash variable and take its reference for creating an object using same bless function??... (0 Replies)
Discussion started by: jatanig
0 Replies

6. Shell Programming and Scripting

PERL - another quick hash of hashes question

Hi, sorry, two hash related questions in one day .. but this has got me a bit stuck. I have a mysql database table that kind of looks like this, the table is called "view1" and a snippet of that table (SELECT'ing just rows with serial number 0629AN1200) is below serial nic_name ... (2 Replies)
Discussion started by: hcclnoodles
2 Replies

7. Shell Programming and Scripting

PERL - printing a hash of hashes to screen

Hi there I have a hash of hashes made up of the following data bge0|100|half|10.36.100.21 bge1|1000|full|10.36.100.22 bge2|1000|full|10.36.100.23 which when i turn into a hash, would look like this inside the system bge0 -> nic_speed -> 100 nic_duplex -> half ... (6 Replies)
Discussion started by: hcclnoodles
6 Replies

8. Shell Programming and Scripting

perl hash of hashes from database

hi there, I have some database output that looks like this SELECT nic_name,nic_duplex,nic_speed,nic_ip FROM network_table WHERE hostname = "server1" result is this (ive delimited with a pipe for ease of reading) bge0|full|1000|10.32.100.1 bge1|full|1000|11.12.101.7 ... (1 Reply)
Discussion started by: hcclnoodles
1 Replies

9. Shell Programming and Scripting

Print Entire hash list (hash of hashes)

I have a script with dynamic hash of hashes , and I want to print the entire hash (with all other hashes). Itried to do it recursively by checking if the current key is a hash and if yes call the current function again with refference to the sub hash. Most of the printing seems to be OK but in... (1 Reply)
Discussion started by: Alalush
1 Replies

10. Shell Programming and Scripting

Perl hashes "Can't use subscript on private hash"

This is driving me mad, where am I going wrong? The relevant segment of code: sub getndsybcons { my @servers=@{$_}; my @sybservers=@{$_}; my %results; foreach my $server(@servers) { my $biggestsyb; my $biggestsybval=0; ... (9 Replies)
Discussion started by: Smiling Dragon
9 Replies
Login or Register to Ask a Question