in reply to converting "30k" string to integer
Give two arguments on the command line, the first being a number, the second being k, m, g or t, with an optional trailing b.#!/usr/bin/perl -w use strict; my($amt, $units, $availableunits) = @ARGV[0,1], 'kmgt'; $units =~ s/^([$availableunits])(b)?$/ (1000*($2?1.024:1))**index("X$availableunits",$1) /exi; print $amt * $units; print "\n";
|
|---|