Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^4: Searching in an array of arrays

by perl_seeker (Scribe)
on Nov 04, 2004 at 10:20 UTC ( #405144=note: print w/replies, xml ) Need Help??


in reply to Re^3: Searching in an array of arrays
in thread Searching in an array of arrays

Hi,this is (part of)the XML file I am parsing:
- <AnnualWeatherRecord> - <DailyWeatherRecord> <date>1-1-2004</date> - <temperature> <maxdrybulb unit="degrees-centigrade" number="15.0" /> <mindrybulb unit="degrees-centigrade" number="15.0" /> <maxwetbulb unit="degrees-centigrade" number="33.53" /> <minwetbulb unit="degrees-centigrade" number="30.53" /> </temperature> <totalrainfall unit="mm" number="0.5" /> </DailyWeatherRecord> - <DailyWeatherRecord> <date>2-1-2004</date> - <temperature> <maxdrybulb unit="degrees-centigrade" number="15.5" /> <mindrybulb unit="degrees-centigrade" number="15.5" /> <maxwetbulb unit="degrees-centigrade" number="23.14" /> <minwetbulb unit="degrees-centigrade" number="20.14" /> </temperature> <totalrainfall unit="mm" number="0" /> </DailyWeatherRecord> - <DailyWeatherRecord> <date>3-1-2004</date> - <temperature> <maxdrybulb unit="degrees-centigrade" number="16.5" /> <mindrybulb unit="degrees-centigrade" number="16.5" /> <maxwetbulb unit="degrees-centigrade" number="33.53" /> <minwetbulb unit="degrees-centigrade" number="30.53" /> </temperature> <totalrainfall unit="mm" number="0.5" /> </DailyWeatherRecord> - <DailyWeatherRecord> <date>15-1-2004</date> - <temperature> <maxdrybulb unit="degrees-centigrade" number="28.0" /> <mindrybulb unit="degrees-centigrade" number="28.0" /> <maxwetbulb unit="degrees-centigrade" number="33.53" /> <minwetbulb unit="degrees-centigrade" number="30.53" /> </temperature> <totalrainfall unit="mm" number="0.5" /> </DailyWeatherRecord> - <DailyWeatherRecord> <date>16-1-2004</date> - <temperature> <maxdrybulb unit="degrees-centigrade" number="28.8" /> <mindrybulb unit="degrees-centigrade" number="28.8" /> <maxwetbulb unit="degrees-centigrade" number="33.53" /> <minwetbulb unit="degrees-centigrade" number="30.53" /> </temperature> <totalrainfall unit="mm" number="0" /> </DailyWeatherRecord> - <DailyWeatherRecord> <date>1-2-2004</date> - <temperature> <maxdrybulb unit="degrees-centigrade" number="44.25" /> <mindrybulb unit="degrees-centigrade" number="39.25" /> <maxwetbulb unit="degrees-centigrade" number="33.53" /> <minwetbulb unit="degrees-centigrade" number="30.53" /> </temperature> <totalrainfall unit="mm" number="0.5" /> </DailyWeatherRecord> - <DailyWeatherRecord> <date>2-2-2004</date> - <temperature> <maxdrybulb unit="degrees-centigrade" number="50.25" /> <mindrybulb unit="degrees-centigrade" number="49.25" /> <maxwetbulb unit="degrees-centigrade" number="23.14" /> <minwetbulb unit="degrees-centigrade" number="20.14" /> </temperature> <totalrainfall unit="mm" number="0" /> </DailyWeatherRecord> - <MonthlyWeatherRecord> <date>1-2004</date> - <temperature> <maxdrybulb unit="degrees-centigrade" number="33.95" /> <mindrybulb unit="degrees-centigrade" number="23.20" /> <avgdrybulb unit="degrees-centigrade" number="33.95" /> </temperature> <totalrainfall unit="mm" number="0.5" /> </MonthlyWeatherRecord> - <MonthlyWeatherRecord> <date>2-2004</date> - <temperature> <maxdrybulb unit="degrees-centigrade" number="50.25" /> <mindrybulb unit="degrees-centigrade" number="39.25" /> <avgdrybulb unit="degrees-centigrade" number="44.25" /> </temperature> <totalrainfall unit="mm" number="0.5" /> </MonthlyWeatherRecord> </AnnualWeatherRecord>
And this is the code I'm using to parse it and build @data
Subroutine
sub MonthlyMaxTempSpellMessage{ my $month = shift; #print "\n$month"; $month = "-$month-"; #print "\n$month"; my $xp = XML::XPath->new(filename =>'weather_records.xml'); my @data=(); my $nodes = $xp->findnodes("//DailyWeatherRecord [contains(date,'$month')]"); foreach my $node($nodes->get_nodelist){ push @data, [$xp->findvalue(".//date",$node),$xp- >findvalue(".//maxdrybulb /\@number",$node)]; } for my $aref ( @data ) { print "\t [ @$aref ],\n"; }
Main
my $monthmts=1; MonthlyMaxTempSpellMessage($monthmts);
Anything wrong here? What do I need to change in your code to build the required array of arrays?
Thanks
perl_seeker:)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://405144]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2020-11-25 09:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?