LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 05-25-2004, 10:34 PM   #1
smaida
Member
 
Registered: Apr 2004
Location: Richmond, VA - USA
Distribution: Debian
Posts: 62

Rep: Reputation: 15
Perl XML::Simple - Hash Question


Hi,

How would I loop through and access the following data:

Code:
$VAR1 = {
          'site' => [
                    {
                      'website' => 'http://www.site1.com',
                      'status' => '200',
                      'vpn' => 'no'
                    },
                    {
                      'website' => 'http://www.site2.com',
                      'status' => '200',
                      'vpn' => 'no'
                    },
                    {
                      'website' => 'http://www.site3com',
                      'status' => '200',
                      'vpn' => 'yes'
                    }
                  ]
        };
I need to perform a set of actions on each set of data.

The data is created using XML::Simple and the output above was from data::dumper.

Thanks,
Shawn
 
Old 05-25-2004, 11:02 PM   #2
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
Code:
for my $record (@{$VAR1->{site}})  {
    my $website = $record->{website};
    my $status = $record->{status};
    my $vpn = $record->{vpn}
    # do stuff with $website, $status, and $vpn
}
That's untested.
 
Old 05-26-2004, 04:20 AM   #3
smaida
Member
 
Registered: Apr 2004
Location: Richmond, VA - USA
Distribution: Debian
Posts: 62

Original Poster
Rep: Reputation: 15
Hi Aluser,

Thanks alot. That works great.

Shawn
 
  


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
checking for XML::Parser... configure: error: XML::Parser perl module is required for kornerr Linux - General 11 11-16-2008 07:24 AM
simple Perl Question whohasit Programming 3 11-05-2004 10:52 AM
simple Perl question true_atlantis Programming 5 11-18-2003 08:37 PM
Simple Perl Question jacksmash Programming 1 11-13-2003 09:17 PM
Simple Perl question! Please help! jacksmash Programming 4 11-07-2003 05:56 AM

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

All times are GMT -5. The time now is 06:04 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
Open Source Consulting | Domain Registration