LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 06-07-2006, 01:59 PM   #1
faref
LQ Newbie
 
Registered: Jan 2004
Distribution: Slackware, Ubuntu
Posts: 25

Rep: Reputation: 15
Nesting Hashes in Perl.


I've been staring at this all day and it's given me a bit of a headache.

(This is perl not php, but I like the colors )
PHP Code:
@MasterList = ("Hardware","Hardware Overview","Serial Number""123456789");
%
HashMasterList ={@MasterList[0] => {@MasterList[1] => {@MasterList[2] => @MasterList[3]}}};
print 
"The Serial is: $HashMasterList{'Hardware'}->{'Hardware Overview'}->{'Serial Number'}\n"
Why does this not print "The Serial is: 123456789"? I've googled but there does not seem to be much in the way of nesting hashes...especially three deep based off of names stored in an array. Any help would be most appreciated.
 
Old 06-07-2006, 03:00 PM   #2
demon_vox
Member
 
Registered: May 2006
Location: Argentina
Distribution: SuSE 10
Posts: 173

Rep: Reputation: 30
Hi,
I've modificated two things and it worked.
The first one is when you write @MasterList[0]. Remember that you want to access a particular element, and that is a scalar value. So you should put a $ instead of a @ (and with all the @MasterList[ ] of the second asignment).
The second one is that I define the HashMasterList with parentesis instead of brackets. I believe, but I am not sure (and I am a little out of time to check it out), that if you use brackets you are defining a reference to an hash as contrary of direct hash, which would change the syntax from where you are reading an element.

So, that line would end up like this:
Code:
%HashMasterList = ($MasterList[0] => {$MasterList[1] => {$MasterList[2] => $MasterList[3]}});
Hope this is useful
 
Old 06-07-2006, 05:03 PM   #3
faref
LQ Newbie
 
Registered: Jan 2004
Distribution: Slackware, Ubuntu
Posts: 25

Original Poster
Rep: Reputation: 15
wow.

This is only my third day of perl and you've been most helpful, thanks!
 
  


Reply



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
Passing hash of hashes as a parameter (Perl) rose_bud4201 Programming 8 04-21-2005 07:18 PM
weird behaviour with hashes in perl weird_guy Programming 0 06-22-2004 09:51 PM
Bash scripting: Nesting backticks ? Deleriux Programming 1 01-04-2004 02:08 PM
md5 hashes banderson Linux - General 1 10-17-2003 12:06 PM
MD5 hashes ruffneck Linux - General 1 07-08-2002 05:52 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:25 AM.

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
Open Source Consulting | Domain Registration