Hello Johnny!
I still cannot do much with the module. Maybe I'm asking for too much, but could you please help me with this?(thanks for your patience!):
I need to write a subroutine that takes as input the month number e.g. 2 for February, and searches the XML file for the monthly weather record for February, and any month
before it i.e. January.I need to extract the total rainfall amounts from these records and find their sum.
The subroutine returns the month number and the sum in an array.If I needed to look for only the February monthly record or $month='2', I guess the code would look like this:
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 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!
I also need to write another sub, which also takes the month number as input, and searches the daily weather records for that month and extracts the maxdrybulb values . I need to search for each set of 5 (for the time being say, better to make this a variable that can be set) consecutive days where the maxdrybulb values fall in the same range( 'temperature spells' of the month).
The temperature ranges could be defined as for example:
Over 40.0 extremelyhot
35.0 to 39.9 veryhot
30.0 to 34.9 hot
25.0 to 29.9 verywarm
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.,
1-2-2004
5-2-2004
'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.
<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>
All this seems really complicated. I do have some code, but not much. Please help!
Thanks,
perl_seeker:)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.