DESCRIPTION

The Units package is a collection of modules for parsing strings with unit measurements (such as \*(L"12pt\*(R" or \*(L"3 meters\*(R") and converting them to some other unit (such as \*(L"picas\*(R" or \*(L"inches\*(R").

It uses a base package (Units::Base) which does the dirty work. Other modules define what units they handle and how they are related.

\$1

It is intentionally distinct from the Math::Units module. Why? The Math::Units module implies that unit conversions are exact, with one-to-one relationships. This is fine for scientific work. It's even fine for some general purpose/real-world uses (such as converting Fehrenheight to Celcius).

Real-world measurement systems are conflicting. For instance, a \*(L"point\*(R" in typography is equivalent to 1/72 inch, according to PostScript specs and common usage. Other type systems consider it 1/72.27 inch, or 0.01383 inches, or 0.0148 inches. Outside of that context, a point may be 1/120 or 1/144 inch.

Common notations and abbreviations also depend on context. Does \*(L"12 pt\*(R" mean \*(L"12 point\*(R", \*(L"12 parts\*(R" or \*(L"12 pints\*(R"?

Even without conflicts in the definition of a particular unit, there's no need to convert point sizes for fonts into miles or light-years. Typesetters, surveyors and astronomers user different scales as well as systems. Not everyone uses the metric system.

And even less people say things like \*(L"5.25 feet\*(R". Often it's \*(L"5 feet, 3 inches\*(R" or \*(L"5 1/4 feet\*(R".

Despite having ten fingers and toes, people don't think in tens. They think in twos, threes, fours, twelves, and sixteens. And sometimes they use fractional measurements like quarter-inches, sixteenths-of-an-inch, or half-pints.

The purpose of this module is to allow people to use the measurement systems they are familiar with, and that is appropriate to what they are doing. The Units:: hierarchy is an attempt to keep measurement systems in distinct classes. Thus one can have modules for converting between typography units (points, picas) distinct from common units of length (or area, temperature, etc.), specialized units (for Astronomy, Chemistry, Physics, Textiles, Winery, Navigation, etc.) or even traditional or regional systems (Japanese, Chinese, Egyptian, archaic systems, etc.) and to keep conflicting measurement systems distinct. The current distribution contains the following packages:

    Convert::Units::
    ::Base         - a base module that does all of the work
    ::Length       - a module for converting units of length
    ::Temperature  - a module for converting units of temperature
    ::Type         - a module for converting units of type

Units::Base by itself does nothing. Another module needs to use it to create definitions of what units of measurement it handles and how they are related to each other (ie, 1 m = 100 cm).

The base unit also allows for synonym and abbreviations to be defined.

It also allows common \*(L"multiples\*(R" to be defined, so that it can handle things like \*(L"18 half-points\*(R" or \*(L"6 dozen feet\*(R" or even convert millimters to \*(L"sixteenths of an inch\*(R". (It does not yet handle Greek prefixes like centi- or mega- ... those will have to be manually defined.) The current release should be considered \*(L"beta\*(R" until further testing and refinements have been made. Then again, maybe \*(L"alpha\*(R" is more accurate.

The current version does not yet handle fractions such as \*(L"1/2 in\*(R". It should handle decimals such as \*(L"0.5 in\*(R".

Relationships have been rewritten to be handle A(x+b) as well Ax. They may be redone in the future to handle more complex relationships, if the need arises.

Unit names much be defined as all lowercase, since strings are munged with lc() before processing. In other words, if you define a unit name as \*(L"F\*(R" or \*(L"Fahrenheight\*(R" you won't be able to use it. Aside from bug fixes, optimizations, and making the string parsing conform more to the \*(L"manifesto\*(R" above, obvious additions would be modules for converting between units of area, volume, weight... (although if Math::Units does what you need, use that instead.)

An example hierarchy for future modules:

Convert::Units:: ::Length - general measures of length ::Area ::Pressure ::Volume

Convert::Units::Length ::Chinese - specialized regional/traditional systems ::English

Convert::Units::Astronomy ::Length - or Distance...?

Modules should share a common unit (preferably metric) to allow for conversions.

REQUIRED MODULES

Carp

RELATED TO Convert::Base…

Units::Length, Units::Temperature and Units::Type modules, which demonstrate how Units::Base is used.

AUTHOR

Robert Rothenberg <[email protected]>

LICENSE

Copyright (c) 1999-2000 Robert Rothenberg. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.