Skip to end of metadata
Go to start of metadata

$string= LoxBerry::System::bytes_humanreadable(NUMBER $size, STRING $input_factor);

 


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.

Parameters

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:

  • <empty> or omitting the parameter → Bytes
  • "K" → Kilobytes
  • "M" → Megabytes
  • "G" → Gigabytes
  • "T" → Terrabytes

The calculation factor of the function is 1024 (not 1000).

Return value

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.


Usage

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");




  • No labels