473,549 Members | 2,408 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

hash / array / hash

8 New Member
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 2330
miller
1,089 Recognized Expert Top Contributor
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 New Member
Thanks Milller...

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

Keith
Jun 20 '07 #3
miller
1,089 Recognized Expert Top Contributor
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
1577
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. Something like:
5
2008
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", "b" : "2"); doesn't work. Any hints? TIA -- <?php echo 'Just another PHP saint'; ?> Email: rrjanbiah-at-Y!com Blog:...
47
5033
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 are not at all. If you are doing *array", then you have to use only integer values for array index, as it was since ALGOL.
22
4576
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 month I had enough of extra proof that the cat doesn't hount mice anymore in more and more situations. And the surrent sicretisme among array and...
6
4456
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
3188
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 enums. These enums you might imagine would be like OrderPrice=27, OrderQuantity=50, OrderSide=62. There may be a lot of these. So normally what we...
2
2514
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 is best suited for it. My question is Why hash table. why can't we use an array. I thought hash table uses more memory than array. Correct me if am...
9
1834
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 array, looping over the entire array looking for a match is SLOW. So I'm running a hash in parallel, where every time a feature is pushed onto...
5
8159
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
2961
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 $i=0; $i<@input; $i++){ my $hash = $input; print "$i: \n";
0
7467
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7982
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7500
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6066
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5385
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3514
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1961
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1079
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
783
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.