473,395 Members | 1,393 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

hash / array / hash

8
Hi (again !)

I posted a question yesterday just for info on hashrefs which I have read and it makes sense. Putting this into proactive though has now toally confused me !

I have an XML file sucked into a hash via XML::Simple. That's OK. I can see the data using Data::Dumper.

I seem to have a Hash of Arrays, and those Arrays contain another hash.
All I am trying to do is get to the data but every route I take I am getting myself into more confusion.

I have copied a chunk of the code in bwloe so you can tell me what I am missing (and laugh a bit at the same time at a novice !! lol)

Expand|Select|Wrap|Line Numbers
  1. use XML::Simple;
  2. my $xml_hash = XMLin('concorde.xml');
  3. # use Data::Dumper;
  4. # print Dumper($xml_hash);
  5.  
  6. print "first hash : $xml_hash\n";
  7.  
  8. for my $key (keys %{$xml_hash}) {
  9.     print "$key => ${$xml_hash}{$key}\n";
  10.     #output from above is a single key of "ORDER"
  11. }
  12.  
  13. print "test0: ${$xml_hash}{ORDER}[0]\n";
  14. print "test1: ${$xml_hash}{ORDER}[1]\n";
  15.  
  16. my $next_hash = "${$xml_hash}{ORDER}[0]";
  17. print "next hash : $next_hash \n";
  18. for my $key (keys %{$next_hash}) {
  19.     print "$key => ${$next_hash}{$key}\n";
  20. }
  21.  
OK.. the output of the above is:

Expand|Select|Wrap|Line Numbers
  1. first hash : HASH(0x304867a8)
  2. ORDER => ARRAY(0x304b00d0)
  3. test0: HASH(0x30486c1c)
  4. test1: HASH(0x30486d54)
  5. next hash : HASH(0x30486c1c)
  6.  
Something I have done is clearly wrong/stupid etc.

Help !! Once I get one working I'll be fine !

Keith
Jun 19 '07 #1
3 2322
miller
1,089 Expert 1GB
Greetings Keith,

It appears that you have some familiarity with complex data structures. However, just note that the one tutorial that you just be familiar with when manipulating said structures is the following:

perldoc perldsc Data Structures Cookbook

Anyway, your problem lies in the following assignment:

Expand|Select|Wrap|Line Numbers
  1. my $next_hash = "${$xml_hash}{ORDER}[0]";
  2.  
Your assigning $next_hash to the string representation of the hash reference at that location, not the actual reference. Also, it's simply a stylistic difference, but I would refer to that variable like the following:

Expand|Select|Wrap|Line Numbers
  1. my $next_hash = $xml_hash->{ORDER}[0];
  2.  
- Miller
Jun 19 '07 #2
keithl
8
Thanks Milller...

That moved me on past the step I was screaming at !!

Keith
Jun 20 '07 #3
miller
1,089 Expert 1GB
I understand. You welcome :)

- Miller
Jun 20 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jeff Thies | last post by:
I have this: var hash=new Array(); hash='some_value'; hash='some other value'; Whar do you call that in javascript? I know it's possible to define this in one line, but I've forgotten how....
5
by: R. Rajesh Jeba Anbiah | last post by:
I could see that it is possible to have hash array using objects like var hash = {"a" : "1", "b" : "2"}; Couldn't still findout how to declare hash array in Array. var arr = new Array("a" : "1",...
47
by: VK | last post by:
Or why I just did myArray = "Computers" but myArray.length is showing 0. What a hey? There is a new trend to treat arrays and hashes as they were some variations of the same thing. But they...
22
by: VK | last post by:
A while ago I proposed to update info in the group FAQ section, but I dropped the discussion using the approach "No matter what color the cat is as long as it still hounts the mice". Over the last...
6
by: Chang | last post by:
How to get SHA1 or MD5 of a big file (+5MB - 20GB) as I can't read 20GB into memory. -- Chang.
12
by: wxs | last post by:
Many times we have a bunch of enums we have from either different enums or the same enum that will have various numeric values assigned. Rarely will there be collisions in numbering between the...
2
by: Ravi | last post by:
Hi, I am working on a winform app. I need to use an object which can store some information(key/value pairs) and also can be acessed by multiple threads(read/write). From what I heard Hash table...
9
by: IamIan | last post by:
I'm using an array to store map features (name, lat, lon, caption, etc), from which the user can then select an individual feature. The problem is that when thousands of features are stored in the...
5
by: Jeff | last post by:
Lets say we have what I would call a "hash": var HASH =new Array(); HASH='first'; HASH='second'; HASH='third'; I'd like to return that as JSON data. Is there a direct way to do that?
1
by: sixtyfootersdude | last post by:
Good Morning! I am a perl newbie and I think that I am struggling with references. I have an array of references to hashes which I am trying to print. This is what I have: for(my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.