in reply to converting "30k" string to integer

I'd store multipliers in a hash, which is keyed by the end of the string:

my %MULTIPLIERS = ( k => 1024, kb => 1024, g => 1024 * 1024 * 1024, gb => 1024 * 1024 * 1024, ); my $num = '30k'; # or 24g or 29kb, whatever $num =~ s/\A (\d+) ([A-Za-z]{0,2}) \z)/$1/x; my $key = lc $2; $mult = exists $MULTIPLIER{$key} ? $MULTIPLIER{$key} : 1; $num *= $mult;

Update: added lowercase key so that 'g' and 'G' evaluate to the same hash key.

----
I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer

Note: All code is untested, unless otherwise stated