Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Measure temperature outside in Perl

by tobyink (Abbot)
on Feb 06, 2012 at 14:02 UTC ( #952086=note: print w/ replies, xml ) Need Help??


in reply to Measure temperature outside in Perl

Mwahahahaha! It can be done!

use 5.010; use Acme::UseStrict; use Acme::What; use Web::Magic; sub WHAT { 'use strict'; my @args = $_[0] =~ m{\w+}g; my $woeid = pop @args; $woeid = do { warn "If you want to know the weather $woeid, " . "define the YAHOO_WOEID environment variable. " . "Assuming you live where TOBYINK lives" unless exists $ENV{YAHOO_WOEID} && defined $ENV{YAHOO_WOEID}; ($ENV{YAHOO_WOEID} // 26191) } if $woeid =~ m{^(outside|here)$}i; my $unit = $^F==1 ? 'F' : 'C'; # if $^F == 2 then detect unit by locale. Belize and US use Fahren +heit. if ($^F > 1 and $ENV{LC_MEASUREMENT} =~ /^.._(US|BZ)/i) { $unit = 'F'; } my %opts = ( 'w' => $woeid, 'u' => lc $unit, ); my ($temperature) = Web::Magic -> new(q<http://weather.yahooapis.com/forecastrss>, %opts) -> findnodes('//yweather:condition/@temp') -> map(sub { $_->value }); return "$temperature $unit"; } local $^F = 1; my $temperature=what? (i mean outside); say "The temperature is $temperature";


Comment on Re: Measure temperature outside in Perl
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://952086]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2014-12-21 22:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (108 votes), past polls