Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^3: Searching in an array of arrays

by zejames (Hermit)
on Nov 04, 2004 at 09:54 UTC ( [id://405134]=note: print w/replies, xml ) Need Help??


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

I don't understand your first problem. Testing my code here with the @data defined as :
@data = ( [ '1-1-2004', 15.0 ], [ '2-1-2004', 15.5 ], [ '3-1-2004', 16.5 ], [ '4-1-2004', 17.0 ], [ '5-1-2004', 17.5 ], [ '6-1-2004', 18.0 ], [ '7-1-2004', 18.5 ], [ '8-1-2004', 19.0 ], [ '9-1-2004', 19.5 ], ... [ '16-1-2004', 28.8 ]);
does work here. Could you provide code ? Your problem seems to be XML related.

As for the range, you're right, there is problem, that is corrected in the new version, by converting temperature to an integer :
$day->[1] = int $day->[1];

$last_range is used to remember the current range we are in. If that range remains unchanged 5 times, we print the range information.

$first_day is used to remember the first day we saw the temperature of the current range;

HTH

--
zejames

Replies are listed 'Best First'.
Re^4: Searching in an array of arrays
by perl_seeker (Scribe) on Nov 04, 2004 at 10:20 UTC
    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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://405134]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2024-04-25 20:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found