in reply to Re^3: Help with XML::XPath
in thread Help with XML::XPath
I know this seems silly, but how can I set the value of '$pattern' so that the search pattern includes the month passed as a parameter to the sub, as well as all months before it, starting from Jan? Please help!sub RainSoFarMessage{ my $month = shift; $pattern = "$month-"; my $xp = XML::XPath->new(filename => 'weather_records.xml'); my @result = (); my @totrain=(); my $nodes = $xp->findnodes("//MonthlyWeatherRecord [contains(date,'$pattern')]"); foreach my $node($nodes->get_nodelist){ push @totrain,$xp->findvalue(".//totalrainfall/ \@number",$node); } my $total=0; foreach my $t(@totrain){ $total=$total + $t; print "\n$total"; } push @result [$month,$total]; return \@result; }
I need to then build an array of arrays, where each array corresponds to a temperature spell (5 consecutive days with max. temp in the same range) and stores the start date, end date, and the string representing the temp. range('hot','verywarm', etc.). For e.g.,Over 40.0 extremelyhot 35.0 to 39.9 veryhot 30.0 to 34.9 hot 25.0 to 29.9 verywarm
The sub returns this array of arrays to main. Of course right now the xml file above has only 2 daily weather records for each month.My monthly weather records now look like this, with rainfall info added.1-2-2004 5-2-2004 'verywarm'
All this seems really complicated. I do have some code, but not much. Please help!<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>
|
|---|