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

Re: Measure temperature outside in Perl

by oko1 (Deacon)
on Feb 04, 2012 at 22:48 UTC ( #951868=note: print w/replies, xml ) Need Help??

in reply to Measure temperature outside in Perl

Now that you've *asked*, I *suppose* we'll have to tell you The Secret. It's all part of the Conspiracy (but There Is No Conspiracy, of course.)

# Perl itself actually measures the computer's temperature, # subtracts CPU temp, extrapolates the location of the closest # window or door, catches the temp whenever it was last opened, # and uses a heterogenous mean deteriorating sliding semi- # automated average to compute the current temp +-0.0001 degrees. # All part of DWIM, of course. my $leonard_of_quirm_var = perl->secret_built-in_outside-the-room-temp +erature-measuring-device(); print $leonard_of_quirm_var;

Don't tell anyone else, 'K?

Education is not the filling of a pail, but the lighting of a fire.
 -- W. B. Yeats

Replies are listed 'Best First'.
Re^2: Measure temperature outside in Perl
by choroba (Chancellor) on Feb 04, 2012 at 23:10 UTC
    Converting to Celsius or Fahrenheit based on your locale since 5.8.4.

      Converting to Celsius or Fahrenheit based on your locale since 5.8.4.

      Remember you can use the special variable $^F to control this. If set to 0, uses Celsius; if set to 1, uses Fahrenheit; by default it's set to 2 which auto-detects based on your locale. If you don't believe me (and I have no idea why you wouldn't) then run the following on a sufficiently modern perl:

      perl -E'say $^F'

      I hear that 5.16 is going to modularise temperature scales so that you can download custom ones from CPAN, and come bundled with an additional scale for Kelvin.


      Fahrenheit is a funny scale. The Celsius scale is, as everybody knows, based on the freezing and boiling points of water. The freezing point was designated 0; the boiling point 100; and everything in between was divided equally into a hundred degrees. (Although named after Anders Celsius, his scale actually labelled the boiling point 0, and the freezing point 100. The modern Celsius scale was developed after his death and named in his honour.)

      Initially I thought Daniel Gabriel Fahrenheit must have followed a similar process but with a different liquid. After all, its zero doesn't seem to bear any relation to water.

      But actually it turns out he used water after all. However, rather than dividing it into a scale of 100 parts, he used 180, and rather than defining the freezing point of water to be zero, he defined it as 32, because he knew he could achieve a lower zero by mixing water, salt and ammonium.

      This is why, unlike miles versus kilometres, or pounds versus kilograms, you can use a simple formula to convert precisely between Celsius and Fahrenheit.

      $f = 1.8 * $c + 32;

      And it gives you an exact conversion (within the bounds of floating point arithmetic).

      For fun, see what happens when you plug $c = -40 into that.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (11)
As of 2017-02-21 17:09 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (314 votes). Check out past polls.