Index: mythplugins/mythweather/mythweather/scripts/ENVCANParser.pm
===================================================================
--- mythplugins/mythweather/mythweather/scripts/ENVCANParser.pm	(revision 15058)
+++ mythplugins/mythweather/mythweather/scripts/ENVCANParser.pm	(working copy)
@@ -1,5 +1,3 @@
-#!/usr/bin/perl 
-#
 # This script parses the HTML of an Environment Canada weather forecast
 # page as returned from http://www.weatheroffice.gc.ca.
 #
@@ -46,7 +44,7 @@
 
 sub text {
 
-	if (defined $inside{title}) {
+	if (defined($inside{'title'}) && $inside{'title'}) {
 		$_[0] =~ s/\n//sg;
 		$_[0] =~ /(.*),\s*(.*)- 5 Day Weather/;
 		$results{'cclocation'} = "$1, $2";
@@ -54,7 +52,7 @@
 		$results{'6dlocation'} = "$1, $2";
 	}
 
-	if ($inside{h3}) {
+	if (defined($inside{'h3'}) && $inside{'h3'}) {
 		if ($inside{'div-id'} eq "f1") { $results{'date-0'} = $_[0]; }
 		if ($inside{'div-id'} eq "f2") { $results{'date-1'} = $_[0]; }
 		if ($inside{'div-id'} eq "f3") { $results{'date-2'} = $_[0]; }
@@ -64,37 +62,41 @@
 	}
 
 	if ($inside{li}) {
-		if ($inside{'li-class'} eq "low") {
-			if ($inside{'div-id'} eq "f1") { $_[0] =~ /\w* (-?\d*)/; $results{'low-0'} = $1; }
-			if ($inside{'div-id'} eq "f2") { $_[0] =~ /\w* (-?\d*)/; $results{'low-1'} = $1; }
-			if ($inside{'div-id'} eq "f3") { $_[0] =~ /\w* (-?\d*)/; $results{'low-2'} = $1; }
-			if ($inside{'div-id'} eq "f4") { $_[0] =~ /\w* (-?\d*)/; $results{'low-3'} = $1; }
-			if ($inside{'div-id'} eq "f5") { $_[0] =~ /\w* (-?\d*)/; $results{'low-4'} = $1; }
-			if ($inside{'div-id'} eq "f6") { $_[0] =~ /\w* (-?\d*)/; $results{'low-5'} = $1; }
-		}
+		if (defined($inside{'li-class'})) {
+            if ($inside{'li-class'} eq "low") {
+    			if ($inside{'div-id'} eq "f1") { $_[0] =~ /\w* (-?\d*)/; $results{'low-0'} = $1; }
+	    		if ($inside{'div-id'} eq "f2") { $_[0] =~ /\w* (-?\d*)/; $results{'low-1'} = $1; }
+		    	if ($inside{'div-id'} eq "f3") { $_[0] =~ /\w* (-?\d*)/; $results{'low-2'} = $1; }
+			    if ($inside{'div-id'} eq "f4") { $_[0] =~ /\w* (-?\d*)/; $results{'low-3'} = $1; }
+    			if ($inside{'div-id'} eq "f5") { $_[0] =~ /\w* (-?\d*)/; $results{'low-4'} = $1; }
+	    		if ($inside{'div-id'} eq "f6") { $_[0] =~ /\w* (-?\d*)/; $results{'low-5'} = $1; }
+            }
 
-		if ($inside{'li-class'} eq "high") {
-			if ($inside{'div-id'} eq "f1") { $_[0] =~ /\w* (-?\d*)/; $results{'high-0'} = $1; }
-			if ($inside{'div-id'} eq "f2") { $_[0] =~ /\w* (-?\d*)/; $results{'high-1'} = $1; }
-			if ($inside{'div-id'} eq "f3") { $_[0] =~ /\w* (-?\d*)/; $results{'high-2'} = $1; }
-			if ($inside{'div-id'} eq "f4") { $_[0] =~ /\w* (-?\d*)/; $results{'high-3'} = $1; }
-			if ($inside{'div-id'} eq "f5") { $_[0] =~ /\w* (-?\d*)/; $results{'high-4'} = $1; }
-			if ($inside{'div-id'} eq "f6") { $_[0] =~ /\w* (-?\d*)/; $results{'high-5'} = $1; }
+    		if ($inside{'li-class'} eq "high") {
+                if ($inside{'div-id'} eq "f1") { $_[0] =~ /\w* (-?\d*)/; $results{'high-0'} = $1; }
+                if ($inside{'div-id'} eq "f2") { $_[0] =~ /\w* (-?\d*)/; $results{'high-1'} = $1; }
+                if ($inside{'div-id'} eq "f3") { $_[0] =~ /\w* (-?\d*)/; $results{'high-2'} = $1; }
+                if ($inside{'div-id'} eq "f4") { $_[0] =~ /\w* (-?\d*)/; $results{'high-3'} = $1; }
+                if ($inside{'div-id'} eq "f5") { $_[0] =~ /\w* (-?\d*)/; $results{'high-4'} = $1; }
+                if ($inside{'div-id'} eq "f6") { $_[0] =~ /\w* (-?\d*)/; $results{'high-5'} = $1; }
+            }
 		}
 	}
-			
-	if ($inside{div}) {
-		if ($inside{'div-class'} eq "citycondition") { $results{'weather'} = $_[0]; }
 
-		if ($inside{'div-id'} eq "cityobserved") {
-			$_[0] =~ /.* (\d*\:\d*.*)/;
-			$results{'observation_time'} = "Last updated at $1"; 
-			$results{'updatetime'} = "Last updated at $1"; 
-			$results{'observation_time_rfc822'} = rfc822($1);
-		}
-	}
+    if (defined($inside{'div'}) && $inside{'div'}) {
+        if (defined($inside{'div-class'}) && ($inside{'div-class'} eq "citycondition")) { 
+            $results{'weather'} = $_[0]; 
+        }
 
-	if ($inside{dt}) {
+    	if (defined($inside{'div-id'}) && ($inside{'div-id'} eq "cityobserved")) {
+	    	$_[0] =~ /.* (\d*\:\d*.*)/;
+		   	$results{'observation_time'} = "Last updated at $1"; 
+		    $results{'updatetime'} = "Last updated at $1"; 
+    		$results{'observation_time_rfc822'} = rfc822($1);
+    	}
+    }
+
+	if (defined($inside{'dt'}) && $inside{'dt'}) {
 		if ($_[0] =~ /(Temperature)/) { $scratch = 1; return; }
 		if ($_[0] =~ /(Pressure)\/ Tendency/) { $scratch = 2; return; }
 		if ($_[0] =~ /(Visibility)/) { $scratch = 3; return; }
@@ -104,7 +106,7 @@
 		if ($_[0] =~ /(Wind)/) { $scratch = 7; return; }
 	}
 
-	if ($inside{dd}) {
+	if (defined($inside{'dd'}) && $inside{'dd'}) {
 		if ($scratch == 1) { $_[0] =~ /(-?\d*).*/; $results{'temp'} = $1; }
 		if ($scratch == 2) { $_[0] =~ /(\d*\.\d+) kPa.*/; $results{'pressure'} = $1 * 10; }
 		if ($scratch == 3) { $_[0] =~ /(\d*) km/; $results{'visibility'} = $1; }
@@ -132,7 +134,7 @@
 	my $icon;
 
 	# Get Icon
-	if ($inside{'img-src'} =~ /\/weathericons\/(\d*\.gif)/) {
+	if (defined($inside{'img-src'}) && ($inside{'img-src'} =~ /\/weathericons\/(\d*\.gif)/)) {
 		$icon = $1;
 		open(FH, "ENVCAN_icons") or die "Cannot open icons";
 		while (my $line = <FH>) {
@@ -146,13 +148,13 @@
 	}
 			
 	# Current conditions
-	$results{"weather_icon"} = $icon if ($inside{'img-class'} eq "currentimg");
-	$results{"icon-0"} = $icon if ($inside{'img-longdesc'} eq "#f1");
-	$results{"icon-1"} = $icon if ($inside{'img-longdesc'} eq "#f2");
-	$results{"icon-2"} = $icon if ($inside{'img-longdesc'} eq "#f3");
-	$results{"icon-3"} = $icon if ($inside{'img-longdesc'} eq "#f4");
-	$results{"icon-4"} = $icon if ($inside{'img-longdesc'} eq "#f5");
-	$results{"icon-5"} = $icon if ($inside{'img-longdesc'} eq "#f6");
+	$results{"weather_icon"} = $icon if (defined($inside{'img-class'}) && ($inside{'img-class'} eq "currentimg"));
+	$results{"icon-0"} = $icon if (defined($inside{'img-longdesc'}) && ($inside{'img-longdesc'} eq "#f1"));
+	$results{"icon-1"} = $icon if (defined($inside{'img-longdesc'}) && ($inside{'img-longdesc'} eq "#f2"));
+	$results{"icon-2"} = $icon if (defined($inside{'img-longdesc'}) && ($inside{'img-longdesc'} eq "#f3"));
+	$results{"icon-3"} = $icon if (defined($inside{'img-longdesc'}) && ($inside{'img-longdesc'} eq "#f4"));
+	$results{"icon-4"} = $icon if (defined($inside{'img-longdesc'}) && ($inside{'img-longdesc'} eq "#f5"));
+	$results{"icon-5"} = $icon if (defined($inside{'img-longdesc'}) && ($inside{'img-longdesc'} eq "#f6"));
 
 	undef ($inside{'img-class'});
 	undef ($inside{'img-src'});
