Submit a size (e.g. a filesize) and it's input factor (B, KB, MB, GB, TB) to this function. It returns a human-readable string of your size value. |
The first parameter is the number you want to have returned as human-readable string. This can be in bytes, Kilobytes, Megabytes, Gigabytes or Terrabytes. The $size must be a number (without unit).
With the second parameter, tell the function what unit the $size is. Possible strings are:
The calculation factor of the function is 1024 (not 1000).
Returns is a string in human-readable style. The string contains the unit (e.g. 137,4 KB or 2,7 GB). The unit is calculated automatically.
use LoxBerry::System; my $file = "$lbplogdir/mylog.log"; my $filesize = -s $file; print "Filesize is " . LoxBerry::System::bytes_humanreadable($filesize); # Speed was measured in KB my $speed = 123124; print "Speed is " . LoxBerry::System::bytes_humanreadable($speed, "K"); |