Sponsored Content
Top Forums Shell Programming and Scripting PERL - printing a hash of hashes to screen Post 302348882 by hcclnoodles on Sunday 30th of August 2009 09:32:51 AM
Old 08-30-2009
PERL - printing a hash of hashes to screen

Hi there

I have a hash of hashes made up of the following data

Code:
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

Code:
bge0 ->
           nic_speed -> 100
           nic_duplex -> half
           nic_ip -> 10.36.100.21
bge1 ->
           nic_speed -> 1000
           nic_duplex -> full
           nic_ip -> 10.36.100.22
bge2 ->
           nic_speed -> 1000
           nic_duplex -> full
           nic_ip -> 10.36.100.23

but there doesnt seem to be an obvious way of using the print command to just print this all to the screen so i can see whats going on inside the hash. i just have to trust its worked...I found this snippet of code which seems to work on a single hash, but not on a "hash of hashes" like mine ...


Code:
  while ( ($key,$value) = each %hServerData ) {
    print "$key => $value\n";
  }

I get the following when I run it

Code:
$ ./tester.pl
bge0 => HASH(0x88dafc8)
bge1 => HASH(0x88daf28)
bge2=> HASH(0x88db018)

so its printing the value of the hash and finding that its another hash, hence the "HASH(0x88db018)" stuff

Does anybody know how i would be able to adjust the above snippet of code so that it printed something similar to the layout defined above with the top level hash AND the key value pairs of the sub hash?

any help on this would be greatly appreciated

Last edited by hcclnoodles; 08-30-2009 at 10:38 AM..
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. Shell Programming and Scripting

hash of hashes : how to print reference and its internal structure?

#use perl 5.8.5; my %h1=(a=>'b', c=>'d'); my %h2=(a1=>'b1', c1=>'d1'); my $R1=\%h1; my $R2=\%h2; my %h= {$R1, $R2}; my $href=\%h; # hash of hashes foreach my $key (keys %$href){ print "Z::$$href{$key}\n" } When I am trying to print elements of hash of hashes, it prints HASH... (1 Reply)
Discussion started by: shristi
1 Replies

6. 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

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

8. Homework & Coursework Questions

[solved]Perl: Printing line numbers to matched strings and hashes.

Florida State University, Tallahassee, FL, USA, Dr. Whalley, COP4342 Unix Tools. This program takes much of my previous assignment but adds the functionality of printing the concatenated line numbers found within the input. Sample input from <> operator: Hello World This is hello a sample... (2 Replies)
Discussion started by: D2K
2 Replies

9. Shell Programming and Scripting

Perl: Printing null hash values as a " "?

I'm filling in a table of values for grades. I decided to go with reading into a hash from the files but I'm coming up with an error when printing a value that does not exist. I need to know if I can on-the-fly print a space (" ") or blank in place of the grade. Here's what the output should... (2 Replies)
Discussion started by: D2K
2 Replies

10. Shell Programming and Scripting

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... (1 Reply)
Discussion started by: timj123
1 Replies
Digest::MultiHash(3pm)					User Contributed Perl Documentation				    Digest::MultiHash(3pm)

NAME
Digest::MultiHash - XOR based, variable width multiplexing of hashes (a generalized Digest::SV1). SYNOPSIS
use Digest::MultiHash; my $d = Digest::Multihash->new( width => 16, # bytes hashs => ["SHA-512", "Whirlpool"], # see below for arbitrary arguments ); $d->add($data); print $d->hexdigest; DESCRIPTION
This class inherits from Digest::base, and provides generalized digest multiplexing. It will multiplex all calls to "add" to all of it's sub digest objects. Likewise, when the final digest is extracted the digests will be extracted and then XOR'd over eachother according to "width". "width" will default to the width of the first hash if unspecified. "hashes" defaults to "SHA-1" for compatibility reasons. This module is useful for generating keys from passphrases, by supplying the desired width and simply making sure there is enough data from the combined hashes. METHODS
See Digest for the complete API. This module inherits from Digest::base. new This methods accepts a hash reference or an even sized list of parameters named according to the methods. add digest Compute the hash by calling "digest" on all of the subhashes, splitting the result up into "width" sized chunk, and then XORing these together. If the result is not aligned on "width" the result will not be truncated. The shorter string will still be XOR'd with the hash, even if this only affects part of the result. If there are not at least "width" bytes of data in the output of the combined hashes an error is thrown. clone Clones the hash. hashes Get the array of hashes to use. Array values in this will be dereferenced before the call to "new" in Digest to allow passing of arbitrary arguments. Blessed objects (of any class) will be used verbatim. The list of hashes cannot be changed after construction. width Get/set the byte-width to use. SEE ALSO
Digest, Digest::SV1, Digest::SHA1 perl v5.14.2 2009-10-19 Digest::MultiHash(3pm)
All times are GMT -4. The time now is 12:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy