Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
#!/usr/bin/perl use IO::Socket; if ($#ARGV < 0) { die "usage: weather.pl <zipcode | city>\n"; } $server = 'search.weather.yahoo.com'; $serverPort = '80'; $get = '/weather/query.cgi?q='; $zipcode = $ARGV[0]; $remote = new IO::Socket::INET ( Proto=>'tcp', PeerAddr=>$server, PeerPort=>$serverPort, Reuse=>1 ) or die $!; $remote -> autoflush(1); print $remote "GET $get"."$zipcode HTTP/1.0\n\n"; while ( $location = <$remote>) { if ( $location =~ /Location:/ ) { $redir = $location; $redir =~ s/Location: //; } } close $remote; if ($redir eq '') { print "Sorry, unable to gather weather data for $zipcode\n"; exit; } @temp = split(/\//, $redir); $server = $temp[2]; $get = "\/"."$temp[3]"."\/"."$temp[4]"; $remote = new IO::Socket::INET ( Proto=>'tcp', PeerAddr=>$server, PeerPort=>$serverPort, Reuse=>1 ) or die $!; $remote -> autoflush(1); print $remote "GET $get HTTP/1.0\n\n"; while ( $raw = <$remote>) { if ($raw =~ /Appar Temp:/) { $temp = $raw; } elsif ($raw =~ /Humidity:/) { $humidity = $raw; } elsif ($raw =~ /Wind:/) { $wind = $raw; } elsif (($raw =~ /^<font size=\"-2\" face=\"arial\">.+<\/font><\/td +>$/) && ($condFound ne 1)) { $conditions = $raw; $condFound = 1; } elsif ($raw =~ / Forecast<\/title>/) { $city = $raw; } } close $remote; $conditions =~ s/^<font size=\"-2\" face=\"arial\">//; $conditions =~ s/<\/font><\/td>$//; chomp $conditions; $temp =~ s/<tr><td><font size=-1>//; $temp =~ s/<\/font><\/td>//g; $temp =~ s/<td><font size=-1>//; $temp =~ s/<\/tr>//; $temp =~ s/:/: /; $temp =~ s/Appar //; $temp =~ s/&#176\;/ degrees/; chomp $temp; $humidity =~ s/<tr><td><font size=-1>//; $humidity =~ s/<\/font><\/td>//g; $humidity =~ s/<td><font size=-1>//; $humidity =~ s/<\/tr>//; $humidity =~ s/:/: /; $humidity =~ s/% /%/; chomp $humidity; $wind =~ s/<tr><td><font size=-1>//; $wind =~ s/<\/font><\/td>//g; $wind =~ s/<td><font size=-1>//; $wind =~ s/<\/tr>//; $wind =~ s/&nbsp\;/ /; $wind =~ s/:/: /; chomp $wind; $city =~ s/<title>//; $city =~ s/<\/title>//; $city =~ s/Weather Forecast//; chomp $city; print "Weather for $city(( $temp $humidity ) ( $conditions $wind ))\n" +;

In reply to OPPS - Grab weather from yahoo (2) by scribe

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others taking refuge in the Monastery: (8)
    As of 2014-08-21 18:22 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (141 votes), past polls