Data::SIprefixes - This helps with working with numbers with SI prefixed measures.
Version 0.0.0
use Data::SIprefixes; my $sim=Data::SIprefixes->new('3 grams'); print 'Number: '.$sip->numberGet. "\nprefix: ".$sip->prefixGet. "\nmeasure: ".$sip->measureGet. "\nsymbol: ".$sip->symbolGet. "\nuse symbol: ".$sip->symbolUse. "\nstring: ".$sip->string."\n";
While new can properly parse some prefix/measure combos, the ones below are set statically as they can cause confusion.
amp ampere coulomb farad Gy henry kat katal kelvin m metre meter mol mole newton Pa pascal T
Because of this, while it is possible of matching other symbols with out a measure, the ones listed below can't be.
m T
This initiates the object.
One argument is required and that is the string.
my $sip->new('3 kilometer'); if ( $sip->error ){ warn('error:'.$sip->error.': '.$sip->errorString); }
This returns the measure part.
This won't error as long as new did not.
If no measure was found, '' is returned.
my $measure=$sip->measureSet('gram');
This sets the measure. This will accept '' as a valid measure.
$sip->measureSet( $measure ); if ( $sip->error ){ warn('error:'.$sip->error.': '.$sip->errorString); }
This returns the numeric part.
my $error=$sip->numberGet;
This sets the numeric part.
This won't error as long as what you provide a number.
my $error=$sip->numberGet('4');
This returns the current metric prefix.
As long as it new worked with out error, then this will not error.
A return of '', means there is no current prefix.
my $prefix=$sip->prefixGet;
This sets the metric prefix and update the number to reflect that change.
One argument is accepted and it is the new prefix. A value of '' set it to no prefix.
If no prefix is specified, '' is used.
$sip->prefixSet('kilo');
This returns a formatted string of the number, prefix/symbol, and measure.
This will not error as long as the module initialized with out error.
my $string=$sip->string;
This returns the symbol for the prefix.
A return of '', means there is no current prefix and thus no symbol.
my $symbol=$sip->getSymbol;
Returns if the symbol should be used or not.
The returned value is boolean and this is based off of how it is matched.
This will not error as long as the module has initialized with out error.
my $symbolUse=$sim->symbolUse;
Failed to load one of the prefixes.
The string does not begin with a number.
No number specified.
No recognized prefix specified.
No measure specified.
Zane C. Bowers-Hadley, <vvelox at vvelox.net>
<vvelox at vvelox.net>
Please report any bugs or feature requests to bug-data-siprefixes at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Data-SIprefixes. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-data-siprefixes at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Data::SIprefixes
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Data-SIprefixes
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Data-SIprefixes
CPAN Ratings
http://cpanratings.perl.org/d/Data-SIprefixes
Search CPAN
http://search.cpan.org/dist/Data-SIprefixes/
Copyright 2012 Zane C. Bowers-Hadley.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install Data::SIprefixes, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::SIprefixes
CPAN shell
perl -MCPAN -e shell install Data::SIprefixes
For more information on module installation, please visit the detailed CPAN module installation guide.