[prev in list] [next in list] [prev in thread] [next in thread] 

List:       perl-xml
Subject:    Re: Advice on first xml perl program with XML::Simple
From:       Grant McLean <grant () mclean ! net ! nz>
Date:       2004-06-07 19:04:07
Message-ID: 1086635047.2300.13.camel () localhost
[Download RAW message or body]

On Tue, 2004-06-08 at 04:07, Gary Nielson wrote: 
> I am using XML::Simple and just beginning my program. I want to be able to
> pull out by "geocode" the weather for a certain area of country. I have some
> questions.
> 
> use XML::Simple;
> my $config = XMLin('us.xml');
> use Data::Dumper;
> print Dumper($config);
> 
> The program prints out the variable $VAR1. But I do not understand how to
> access the contents of $VAR1 to extract all of the data -- and then pull out
> data for a specific geocode. 

Try:

  foreach my $capinfo (@{$config->{'cap:info'}}) {
    next unless $capinfo->{'cap:area'};
    print $capinfo->{'cap:area'}->{'cap:geocode'}, "\n";
    print $capinfo->{'cap:area'}->{'cap:areaDesc'}, "\n";
    print $capinfo->{'cap:event'}, "\n";
  }

> Can anyone point me to some examples or a
> tutorial that will illustrate how this is done? I have had experience
> working with scalars, arrays and hashes but I am thinking this is more
> complicated and I could use some pointers on how to proceed.

It sounds like your not too comfortable with Perl references and things 
like Arrays of Hashes or Hashes of Hashes.  The Perl documentation comes
with a tutorial on references:

  http://www.perldoc.com/perl5.8.4/pod/perlreftut.html

This article give more examples and pointers for avoiding common 
pitfalls with XML::Simple:

  http://www.perlmonks.org/index.pl?node_id=218480

Regards
Grant

_______________________________________________
Perl-XML mailing list
Perl-XML@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic