#!/usr/bin/perl use XML::Simple; use Data::Dumper; $file = "55337.xml"; $xdoc = XML::Simple->new(); $doc = $xdoc->XMLin( $file ); #print Dumper( $doc ); # # Locate variables # $temp = $doc->{temp_f}; $heat = $doc->{heat_index_f}; $windchill = $doc->{windchill_f}; $wind_dir = $doc->{wind_dir}; $wind_mph = $doc->{wind_mph}; $humid = $doc->{relative_humidity}; $icon = $doc->{icon_url_name}; $weather = $doc->{weather}; $obs_time = $doc->{observation_time}; # # Tweak variables as needed # $index = $windchill; if ( $index eq "NA" ) { $index = $heat; } if ( $index eq "NA" ) { $index = $temp; } if ( $wind_mph eq "NA" ) { $wind_mpg = 0; } else { @windinfo = split( /\./, $wind_mph ); $wind_mph = $windinfo[ 0 ]; } if ( $wind_dir eq "NA" ) { $wind_dir = "Calm"; } $wind_dir =~ s/Northeast/NE/g; $wind_dir =~ s/Northwest/NW/g; $wind_dir =~ s/Southeast/SE/g; $wind_dir =~ s/Southwest/SW/g; $obs_time =~ s/Last //g; $obs_time =~ s/ on /: /g; $obs_time =~ s/ CDT//g; $obs_time =~ s/ CST//g; $obs_time =~ s/am/AM/g; $obs_time =~ s/pm/PM/g; $obs_time =~ s/\ /_/g; $weather =~ s/\ /_/g; # # Dump output all on one line # The PNG file converter will parse it out # Make sure to quote longer strings # if ( $temp >= 32 ) { printf( "%sF_(%s_Heat_Fact) ", $temp, $index ); } else { printf( "%sF_(%s_Chill_Fact) ", $temp, $index ); } printf( "%s_At_%d_MPH ", $wind_dir, $wind_mph ); printf( "%s%% ", $humid ); printf( "%s ", $icon ); printf( "%s ", $weather ); printf( "%s\n", $obs_time ); exit;