LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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
 
LinkBack Search this Thread
Old 11-02-2006, 07:36 PM   #1
rjcrews
Member
 
Registered: Apr 2004
Distribution: Debian
Posts: 193

Rep: Reputation: 30
Accessing perl array


Hi all,

How do I access the 'Name' field of the array?
I am using Data::Dumper, this is the output when I use the following (read from XML):

print Data::Dumper($tree);

Code:
[
          {
            'desc' => {},
            'content' => [
                           {
                             'desc' => {
                                           'Name' => 'John',
                                           'Date' => 'September 2006',
                                           'Color' => 'Blue',
                                           'Success' => 'TRUE',
                                           'TimeStamp' => '02-SEP-06 07:30 PM',
                                           'Version' => '.25'
                                         },
                             'text' => [],
                             'name' => 'Application'
                           }
                        ]
           }
]
Thanks in advance,
 
Old 11-02-2006, 08:51 PM   #2
demon_vox
Member
 
Registered: May 2006
Location: Argentina
Distribution: SuSE 10
Posts: 173

Rep: Reputation: 30
I am just guessing a bit, but I would try with:

Code:
$tree[0]{'content'}[0]{'desc'}{'Name'}
I might be missing a -> because its late and I am tired hehehhe

Still, I hope this is useful!
Cheers!
 
Old 11-02-2006, 09:55 PM   #3
chrism01
Guru
 
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 6.2, Centos 5.8
Posts: 11,740

Rep: Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905
Actually, the (2nd) 'desc' hash key is at the same level as 'Name', so drop that bit.
 
Old 11-03-2006, 07:33 AM   #4
demon_vox
Member
 
Registered: May 2006
Location: Argentina
Distribution: SuSE 10
Posts: 173

Rep: Reputation: 30
Hi chrism01... be aware that there is a 'name' key and a 'Name' key. I think that rjcrews wanted the second one (because he wrote it with an capitalized). So the 'desc' is necesary if rjcrews wants to access "John". And you would be right that it is superfluous if he wants to access "Application".
I think it is the first case, but thats not for me to say
Either way, I am glad that I didnt missed any -> heheheheh

Cheers!
 
Old 11-05-2006, 05:01 PM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 6.2, Centos 5.8
Posts: 11,740

Rep: Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905
Good call. If it was me I'd make an effort to have var/key names that differed more...
Maintaining that sort of stuff would be b*tch.
 
Old 11-08-2006, 07:16 PM   #6
rjcrews
Member
 
Registered: Apr 2004
Distribution: Debian
Posts: 193

Original Poster
Rep: Reputation: 30
Thx for the reply...helped a ton. The [0] part was what I had wrong.
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash Scripting - Accessing Array Indices Jus144tice Programming 6 10-22-2006 09:20 PM
Problem Accessing Large RAID Array FlyingPenguin128 Debian 1 05-16-2005 10:51 PM
Help accessing data on NTFS raid array Qwindelzorf Linux - Hardware 2 01-15-2005 02:34 PM
PHP: accessing unnamed array mrtwice Programming 8 04-28-2004 11:14 AM
PERL: Size of an array of an Array inspleak Programming 2 03-10-2004 02:24 PM


All times are GMT -5. The time now is 02:49 PM.

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