in reply to Re: why is this code bad under -w option?
in thread why is this code bad under -w option?

thanks dave... that's a super cool way of doing it...
  • Comment on Re: Re: why is this code bad under -w option?

Replies are listed 'Best First'.
Re: Re: Re: why is this code bad under -w option?
by Not_a_Number (Prior) on Jul 28, 2003 at 19:02 UTC

    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