Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

♥ perl

if your terminal does not support unicode (I just discovered that PM code blocks do not...), consider changing the i subroutine to be something more visible

#!/usr/bin/perl -w use strict; use encoding 'utf8'; use Weather::Google; use Math::Units qw/convert/; my $LOCATION = "Nowhere"; # set to city name or postal code my $gw = new Weather::Google($LOCATION); # single-character icons for weather conditions # returns one string with one icon per argument sub i { my $i=''; $i .= /sun/i ? chr 0x2600 : /cloud/i ? chr 0x2601 : /rain|shower/i ? chr 0x2602 : /snow/i ? '*': $_ foreach @_; # the above regexes probably don't cover ALL conditions # but they do cover the ones I have seen over the past few days return $i } # format a temperature # originally the second argument was $f but I found that # I had to convert the temperature much more than I had to # not convert the temperature. If you are one of those types # that thinks in non-SI units, you might want to change that. sub t { my ($t, $c) = @_; return int($c ? $t : convert($t,'F','C')) . chr 0x00b0; } print '[', t($gw->temp_c,1), '(',t($gw->forecast(0,'high')), '/', t($gw->forecast(0,'low')), ')', i($gw->forecast(0,'condition')), '|', i($gw->forecast(1,'condition')), t($gw->forecast(1,'high')), '/', t($gw->forecast(1,'low')), ']';

The above script produces something like [17(18/5)|23/11] A newline is omitted because the script's output is combined with other scripts' outputs to create a single string of statuses and notifications. If you want to run it alone on the command line, I suggest adding ;echo to the end of your invocation.

Thanks to Daniel LeWarne for the module!

$,=qq.\n.;print q.\/\/____\/.,q./\ \ / / \\.,q.    /_/__.,q..
Happy, sober, smart: pick two.

In reply to Google Weather for dwm by xyzzy

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2021-05-17 16:20 GMT
Find Nodes?
    Voting Booth?
    Perl 7 will be out ...

    Results (158 votes). Check out past polls.