Perl Monk, Perl Meditation PerlMonks

### Comment on

 Need Help??

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.

In reply to Re^3: Measure temperature outside in Perl (OT) by tobyink
in thread Measure temperature outside in Perl by chessgui

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

• Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
• Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
• Read Where should I post X? if you're not absolutely sure you're posting in the right place.
• Please read these before you post! —
• Posts may use any of the Perl Monks Approved HTML tags:
a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
• You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
 For: Use: & & < < > > [ [ ] ]
• Link using PerlMonks shortcuts! What shortcuts can I use for linking?
• See Writeup Formatting Tips and other pages linked from there for more info.

Create A New User
Chatterbox?
 [choroba]: Low-end is defined as the Perl that generates millions of income [choroba]: sorry, that's high-end, of coursse [choroba]: low end, in my talk, will be code that "we don't touch because it works" and noone knows why [choroba]: I want to present the most bizzare bugs and misfeatures I met when working for a large financial institution [choroba]: I already gave a similar talk to my friends in a pub and at an internal conference at work and people liked it, so maybe... [choroba]: LanX: That's the heritage, I can't do anything else [RonW]: Sounds like some system my employer has "It does exactly what we need it to do and can't afford to risk anything we can't prove is 100% compatible" [marto]: choroba sounds interesting [RonW]: james28909 Why not write a Perl program to do the task? [choroba]: RonW Yes, but then, one day, they needed to switch from FTP to SFTP, and... but I can't give the whole talk away here :)

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (11)
As of 2017-05-22 21:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
My favorite model of computation is ...

Results (174 votes). Check out past polls.