Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 09-06-2006, 03:35 PM   #1
Registered: Oct 2003
Location: Greece
Posts: 260

Rep: Reputation: 30
Perl hash of hashes

I am new in Perl and im trying to understand the hash of hashes. Unfortunately my text book or various man pages do not clarify ( or
simply i dont get it) my confusion.

In the following line:
my ($source, $destination, $bytes) = split;
$total_bytes{$source} {$destination} += $bytes;

i have a hash %total_bytes . Can you explain the 2 pairs of curly brackets?

Is this an anonymous hash where keys and values are set by the split function?

for simple hashes it would have been $total_bytes{'key'} ='value'

so because this is more complicated we add not only the value($destination) but the key($source) as well

What do you think
Old 09-06-2006, 08:02 PM   #2
Senior Member
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 78
$total_bytes{$source} {$destination}
Well, you said yourself it is a two-dimensional hash.

{$source} is assigning the value of $source to the key of the main hash, and {$destination} is assigning the value of $destination to the key of the hash within the main hash. Make sense?

%total_bytes is a hash of which one key is {$source} whose value is another hash of which the {$destination} key's value is += $bytes
Old 09-07-2006, 05:43 AM   #3
Registered: Oct 2003
Location: Greece
Posts: 260

Original Poster
Rep: Reputation: 30
Thank you bulliver


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl hashes ShaqDiesel Programming 6 08-09-2006 03:54 AM
Nesting Hashes in Perl. faref Programming 2 06-07-2006 06:03 PM
Using hash value as key for other hash in Perl scuzzman Programming 6 02-14-2006 06:08 PM
Passing hash of hashes as a parameter (Perl) rose_bud4201 Programming 8 04-21-2005 08:18 PM
weird behaviour with hashes in perl weird_guy Programming 0 06-22-2004 10:51 PM

All times are GMT -5. The time now is 10:20 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration