Weather::Underground - Perl extension for retrieving weather information from


        use Weather::Underground;

        $weather = Weather::Underground->new(
                place   =>      "Montreal, Canada",
                debug           =>      0
                || die "Error, could not create new weather object: $@\n";

        $arrayref = $weather->getweather()
                || die "Error, calling getweather() failed: $@\n";

        foreach (@$arrayref) {
                print "MATCH:\n";
                while (($key, $value) = each %{$_}) {
                        print "\t$key = $value\n";


Weather::Underground is a perl module which provides a simple OO interface to retrieving weather data for a geographic location. It does so by querying and parsing the returned results.



new() creates and returns a new Weather::Underground object.

"hashref" is a reference to a hash.

Required keys in the hash:


Optional keys in the hash:


"place" key should be assigned the value of the geographical place you would like to retrieve the weather information for. The format of specifying the place really depends on more than it depends on this perl module, however at the time of this writing they accept 'City', 'City, State', 'State', 'State, Country' and 'Country'.

"debug" key should be set to 0 or 1. 0 means no debugging information will be printed, 1 means debug information will be printed.



getweather() is used to initiate the connection to, query their system, and parse the results.

If no results are found, returns undef;

If results are found, returns an array reference. Each element in the array is a hash reference. Each hash contains information about a place that matched the query;

Each hash contains the following keys:

        (the exact place that was matched)

        (the temperature in celsius)

        (the temperature in fahrenheit)

        (humidity percentage)

        (a 1-3 word sentence describing overall conditions, example: 'Partly cloudy')


Your query may result in more than 1 match. Each match is a hash reference added as a new value in the array which getweather() returns the reference to.


Example 1: Print all matching information

        See SYNOPSIS

Example 2: Print the Celsius temperature of the first matching place

        use Weather::Underground;

        $weather = Weather::Underground->new(
                place   =>      "Montreal",
                debug           =>      0
                || die "Error, could not create new weather object: $@\n";

        $arrayref = $weather->getweather()
                || die "Error, calling getweather() failed: $@\n";

        print "The celsius temperature at the first matching place is " . $arrayref->[0]->{celsius} . "\n";


All methods return something that evaluates to true when successful, or undef when not successful.

If the constructor or a method returns undef, the variable $@ will contain a text string containing the error that occurred.


Mina Naguib,