Hello,
I am using XML::XPath to parse an xml file which I've put at the bottom of the post.

In the following code while trying to find the sum of all the elements in @totrain and print it,I keep getting the
following error. Any suggestions on how to remove this?

Code
sub RainSoFarMessage{ my $ulimit = shift; #print "\n$ulimit"; my $xp = XML::XPath->new(filename => 'weather_records.xml'); my @totrain=(); my $nodes; for ($month=1;$month<=$ulimit;$month++){ #print "\n$month"; my $pattern = "$month-"; #print "\n$pattern"; $nodes = $xp->findnodes("//MonthlyWeatherRecord [contains(date,'$pattern')]"); foreach my $node($nodes->get_nodelist){ push @totrain,$xp->findvalue(".//totalrainfall/ \@number",$node); } } #print "\n@totrain"; my $total=0; #print "\n$total"; foreach my $t(@totrain){ #print "\n$t"; $total=$total + $t; #print "\n$total"; } return $total; }
Main
my $monthrs = 2; my $totalrs = RainSoFarMessage($monthrs); #print "\n$totalrs"; my @RainSoFarMesg=(); push @RainSoFarMesg,$monthrs,$totalrs; #print "\n@RainSoFarMesg";
Error
Operation `+': no method found, left argument has no overloaded magic, right argument in overloaded package XML::XPath::Literal at C:\..\ +..\xmlrecord_parse.pl line 480. Tool completed with exit code 255
Line 480 is this:

$total=$total + $t;

Any help would be appreciated.
Thanks,
perl_seeker :)
weather_records.xml - <AnnualWeatherRecord> - <DailyWeatherRecord> <date>1-1-2004</date> - <temperature> <maxdrybulb unit="degrees-centigrade" number="33.95" /> <mindrybulb unit="degrees-centigrade" number="30.95" /> <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="23.34" /> <mindrybulb unit="degrees-centigrade" number="23.20" /> <maxwetbulb unit="degrees-centigrade" number="23.14" /> <minwetbulb unit="degrees-centigrade" number="20.14" /> </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>

In reply to Error with XML::XPath::Literal by perl_seeker

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.