Just after posting, I realised that I could make it more maintainable:
my %convert = ( KB => 10,
MB => 20,
GB => 30 );
my $num;
{
print "Enter the block size\n (example: 400KB, 10MB, 1GB): ";
my $block_size = uc <STDIN>;
print "Invalid block type specified!\n\n" and redo
unless $block_size =~ /^(\d+)([A-Z]B)$/ # Changed
and defined $convert{$2}; # here
$num = $1 * 2 ** $convert{$2};
}
print $num;
That way, it could be more easily be adapted to include terabytes, by just adding TB => 50 to the %convert hash, and then, a few months later :), the same for whatever comes after terabytes...
dave |