Sam Kington >
Silly-StringMaths-0.13 >
Silly::StringMaths

Module Version: 0.13
Silly::StringMaths - Perl extension for doing maths with strings

use Silly::StringMaths qw(add subtract multiply divide exponentiate); # Add two positive numbers - returns ABFOOR print add("FOO", "BAR"); # Add a generally positive number and a negative number # - returns ot print add("FNoRD", "yncft"); # Subtract several numbers from a rather large one # - returns accdeiiiiloopssu print subtract("Supercalifragilisticepsialidocious", "stupid", "made", "up", "word"); # Multiply two negative numbers - returns AAACCCCCCEEELLLNNN print multiply("cancel", "out"); # Divide two numbers - returns AAA print divide("EuropeanCommission", "France"); # Confirm Pythagorus' theorum - returns nothing print subtract(exponentiate("FETLA", "PI"), exponentiate("TLA", "PI"), exponentiate("ETLA", "PI"));

Silly::StringMaths provides support for basic integer mathematics, using strings rather than numbers. Upper-case letters are positive, lower-case letters are negative, so ABCDEF would be 6 (but WOMBAT would also be 6), whereas `positive`

would actually be -8. Mixed-case is also possible, so Compaq is actually -5. Most methods return a canonicalised version of the string - e.g. `ampq`

rather than `Compaq`

(mixed case removed, the result sorted alphabetically).

The behaviour of other characters is as yet undefined, but be warned that non-alphabetical characters may be reserved for floating point or imaginary numbers.

Actual numbers (i.e. the characters 0 to 9) will *never* be used by this module.

Takes an array of strings, returns the sum.

Takes a string, subtracts all other supplied strings from it and returns the result.

Takes a string and multiplies it by all the other strings, returning the resulting product.

Takes a string, and divides it by all the other strings, returning the result. Results are rounded down.

Takes a number, raises it to the appropriate power, as specified by the other arguments. Returns the result. (Note that some textual information is lost here - the result will be either `A`

s or `a`

s).

Takes a string with, potentially, a mix of upper-case and lower-case letters, and returns a sorted string that is unmistakeably either positive or negative.

Returns the sign of a number as either 1, 0 or -1 (as a string, obviously).

Returns whether the supplied string is negative or not

Takes a *reference* to a number, inverts it.

Sam Kington, sam@illuminated.co.uk

perl(1).

syntax highlighting: