Fluent numbers with Acme::Numbers

Inspired by a post in the Beautiful Code blog, Simon Wistow created Acme::Numbers, which lets you do cleverness like this:

use Acme::Numbers;

print two.hundred."\n";               # prints 200
print forty.two."\n";                 # prints 42
print zero.point.zero.five."\n";      # prints 0.05
print four.pounds.fifty.five."\n";    # prints "4.55"
print four.pounds.fifty.pence."\n";   # prints "4.50"
print four.dollars.fifty.cents."\n";  # prints "4.55"

You probably wouldn't want to do this in production code, but like the best of Damian Conway's not-useful-but-thought-provoking modules, it may spark some ideas that you can apply to more useful situations. If nothing else, the source is a fine lesson in overloading and method importing.

Categories:

1 Comments

notbenh said:

seems like theres an error in the POD:

print four.dollars.fifty.cents."\n"; # prints "4.55"

shouldn't that be:

print four.dollars.fifty.cents."\n"; # prints "4.50"

other then that it's a neat concept.

Leave a comment

About this Entry

This page contains a single entry by Andy Lester published on January 27, 2008 8:08 PM.

Vim tricks for Perl was the previous entry in this blog.

Put your work under version control today is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Other Perl Sites

Other Swell Blogs

  • geek2geek: An ongoing analysis of how geeks communicate, how we fail and how to fix it.