#!/usr/bin/perl use strict;
use warnings;
use constant TB => 2**40;
use constant GB => 2**30;
use constant MB => 2**20;
use constant KB => 1024;
my $byte = '800'; # 800 Byte
printf("%s\n", human_readable($byte));
$byte += 1024; # plus ein Kilobyte => 1824 Byte
printf("%s\n", human_readable($byte));
$byte *= 1e3; # mal 1000 => 1824000 Byte
printf("%s\n", human_readable($byte));
sub human_readable {
$_[0] >= TB && return sprintf("%.03f TB", $_[0] / TB);
$_[0] >= GB && return sprintf("%.03f GB", $_[0] / GB);
$_[0] >= MB && return sprintf("%.03f MB", $_[0] / MB);
$_[0] >= KB && return sprintf("%.03f kB", $_[0] / KB);
return "$_[0] B";
}
Grusz coax.