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

Download:
Silly-StringMaths-0.13.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.13   Source  

NAME ^

Silly::StringMaths - Perl extension for doing maths with strings

SYNOPSIS ^

  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"));

DESCRIPTION ^

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.

BASIC METHODS ^

add

Takes an array of strings, returns the sum.

subtract

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

multiply

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

divide

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

exponentiate

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 As or as).

USEFUL TOOLBOX METHODS ^

normalise

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.

sign

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

negative

Returns whether the supplied string is negative or not

invert

Takes a reference to a number, inverts it.

AUTHOR ^

Sam Kington, sam@illuminated.co.uk

SEE ALSO ^

perl(1).

syntax highlighting: