MAN page from Mandrake Other perl-Convert-SciEng-0.90-1.i386.rpm
SciEng
Section: User Contributed Perl Documentation (3)
Updated: perl 5.004, patch 04
Index NAME
Convert::SciEng - Convert `numbers' with scientific postfixes
SYNOPSIS
#!/usr/local/bin/perl -w
use strict; use Convert::SciEng
my $c = Convert::SciEng->new('spice'); my $s = Convert::SciEng->new('si'); print "Scalar\n"; print $c->unfix('2.34u'), "\n\n"; print "Array\n"; print join "\n", $c->unfix(qw( 30.6k 10x 0.03456m 123n 45o)), "\n";
##Note, default format is 5.5g print "Default format is %5.5g\n"; print join "\n", $c->fix(qw( 35e5 0.123e-4 200e3 )), ""; $c->format('%8.2f'); print "Change the format is %8.2g\n"; print join "\n", $c->fix(qw( 35e5 0.123e-4 200e3 )), ""; print "Check out the SI conversion\n"; print join "\n", $s->unfix(qw( 30.6K 10M 0.03456m 123n 45o)), "";
REQUIRES
perl5.004_04 or greater, Carp
I'm sorry if you get bit by the 5.004_04 but I believe in theCathedral model. Keep current or suffer the penalties.
DESCRIPTION
Convert::SciEng supplies an object for converting numbers to and fromscientific notation with user-defined formatting. Two different stylesof fix are supported, standard SI and SPICE:
SPICE = P T g x k '' m u n p f a SI = P T G M K '' m u n p f a Fix = 1e15 1e12 1e9 1e6 1e3 1e0 1e-3 1e-6 1e-9 1e-12 1e-15 1e-18
Methods are supplied for creating the object and defining which fix styleit will use, and defining for format of numbers as they are converted toscientific notation.
METHODS
Creation
- Convert::SciEng->new('style');
- Creates and returns a new Number::SI object of the appropiate style,either 'si' or 'spice'. The styles aren't case sensitive
- $fix->format(FORMAT);
- Sets the format of number converter TO fix to be FORMAT.FORMAT is any valid format to sprintf, like '%5.5g' or '%6.4e'.The default format is '%5.5g'.
Conversion
- $fix->fix(0.030405); # 30.405m
- Convert a number to scientific notation with fixes.Returns a string in the format given to it with the fix appended tothe end. Also works with arrays, with an array of strings beingreturned.
- $fix->unfix('12u'); # 12e-06
- Convert a string from scientific notation. Returns a number inexponential format. Also works with arrays, with an array of numbersbeing returned.
Note, by examining the module it should be relatively easy to figure outhow to create an object for any other scientific notation abbreviations.If you think it is something that might be useful to others, thenemail me and I'll add it to the module.
DIAGNOSTICS
- Unrecognized mode: MODE
- (F) Generated when you try specify an illegal mode like so:
$a = Convert::SciEng->new('foo');
- Illegal printf format: FORMAT
- (F) An illegal format was specified. Valid formats must match the followingregexp:
/^\%\d+(\.\d+)?([scduxoefg]|l[duxo])$/
AUTHOR
Colin Kuskie, colinkAATTlatticesemi.com
KUDOS
Many thanks to Steven McDougall for his comments about the content andstyle of my module and for sending me his templates for modulecreation. They can be found at:
http://world.std.com/~swmcd/steven/Perl/index.html
and I highly recommend them for beginning module writers.
Also thanks to Tom Christiansen for the perltoot podpage.
Index
- NAME
- SYNOPSIS
- REQUIRES
- DESCRIPTION
- METHODS
- DIAGNOSTICS
- AUTHOR
- KUDOS
This document was created byman2html,using the manual pages.