I am very new to Perl and wrote this very simple to convert bytes to KB to MB to GB. So far it's working fine. But I tried to use "%g" in place of "%f" - which according to Learning Perl 4th ed. automatically
chooses float, integer etc. But it was not giving desired output. If anyone could tell me why I can't seem to use %g and also make some comments on the current code then that would be much appreciated.
Here's the code
Code:
#!/usr/bin/perl
use strict;
use warnings;
print "enter the value\n";
chomp (my $value=<STDIN>);
my $kilo = $value/1024;
my $mega = $kilo/1024;
my $giga = $mega/1024;
print "the value is $value\n";
printf "%0.2f KB\n", $kilo;
printf "%0.2f MB\n", $mega;
printf "%0.2f GB\n", $giga;