inblosam has asked for the wisdom of the Perl Monks concerning the following question:
Of course I will be putting in some dynamic XML when I get this to work, so I need to know how many elements were returned so I can get city, state, and zip information out for each entry. Here are the results of the above code, and obviously the count is 1 because that is how many arrays there are. I am sure it is not overly complicated, I have just tried and tried to no avail.#!/usr/bin/perl -w use strict; use XML::Simple; my $xml = qq|<?xml version="1.0" encoding="utf-8"?> <NewDataSet> <Table> <CITY>Provo</CITY> <STATE>UT</STATE> <ZIP>84601</ZIP> <AREA_CODE>801</AREA_CODE> <TIME_ZONE>M</TIME_ZONE> </Table> <Table> <CITY>Provo</CITY> <STATE>UT</STATE> <ZIP>84605</ZIP> <AREA_CODE>801</AREA_CODE> <TIME_ZONE>M</TIME_ZONE> </Table> <Table> <CITY>Provo</CITY> <STATE>SD</STATE> <ZIP>57774</ZIP> <AREA_CODE>605</AREA_CODE> <TIME_ZONE>C</TIME_ZONE> </Table> <Table> <CITY>Provo</CITY> <STATE>KY</STATE> <ZIP>42267</ZIP> <AREA_CODE>502</AREA_CODE> <TIME_ZONE>E</TIME_ZONE> </Table> </NewDataSet>|; my $perl = XMLin($xml); use Data::Dumper; my @table = $perl->{Table}; my @newtable = $table[0]; my $count = @newtable; print Dumper(\@newtable); print "Count is $count\n"; print "State is $newtable[0][3]{STATE}\n";
$VAR1 = [ [ { 'STATE' => 'UT', 'ZIP' => '84601', 'AREA_CODE' => '801', 'TIME_ZONE' => 'M', 'CITY' => 'Provo' }, { 'STATE' => 'UT', 'ZIP' => '84605', 'AREA_CODE' => '801', 'TIME_ZONE' => 'M', 'CITY' => 'Provo' }, { 'STATE' => 'SD', 'ZIP' => '57774', 'AREA_CODE' => '605', 'TIME_ZONE' => 'C', 'CITY' => 'Provo' }, { 'STATE' => 'KY', 'ZIP' => '42267', 'AREA_CODE' => '502', 'TIME_ZONE' => 'E', 'CITY' => 'Provo' } ] ]; Count is 1 State is KY
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Managing data after XML::Simple...count elements
by japhy (Canon) on Jul 02, 2004 at 16:07 UTC | |
by inblosam (Monk) on Jul 02, 2004 at 16:30 UTC | |
|
Re: Managing data after XML::Simple...count elements
by grantm (Parson) on Jul 05, 2004 at 06:20 UTC | |
by inblosam (Monk) on Jul 06, 2004 at 21:59 UTC |