LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices



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

Rep: Reputation: 30
Perl hash of hashes


Hi
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
bulliver
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: 77
Quote:
$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?

IE:
%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
props666999
Member
 
Registered: Oct 2003
Location: Greece
Posts: 260

Original Poster
Rep: Reputation: 30
Thank you bulliver
 
  


Reply


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 03:14 PM.

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