Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

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<>, %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";

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://952086]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2018-01-23 21:07 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (254 votes). Check out past polls.