Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

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

Comment on Re: Measure temperature outside in Perl
Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2015-10-04 12:25 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (102 votes), past polls