Number::Bytes::Human v.0.07

Advertisement
Advertisement

Number::Bytes::Human is a Perl module that can convert byte count to human readable format. SYNOPSIS use Number::Bytes::Human qw(format_bytes), $size = format_bytes(0), # 0 $size = format_bytes(2*1024), # 2.0K $size = format_bytes(1_234_890, bs => 1000), # 1.3M $size = format_bytes(1E9, bs => 1000), # 1.0G # the OO way $human = Number::Bytes::Human->new(bs => 1000, si => 1), $size = $human->format(1E7), # 10MB $human->set_options(zero => -), $size = $human->format(0), # - THIS IS ALPHA SOFTWARE: THE DOCUMENTATION AND THE CODE WILL SUFFER CHANGES SOME DAY (THANKS, GOD!). This module provides a formatter which turns byte counts to usual readable format, like 2.0K, 3.1G, 100B. It was inspired in the -h option of Unix utilities like du, df and ls for "human-readable" output. From the FreeBSD man page of df: http://www.freebsd.org/cgi/man.cgi?query=df "Human-readable" output. Use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte in order to reduce the number of digits to four or fewer using base 2 for sizes. byte B kilobyte K = 2**10 B = 1024 B megabyte M = 2**20 B = 1024 * 1024 B gigabyte G = 2**30 B = 1024 * 1024 * 1024 B terabyte T = 2**40 B = 1024 * 1024 * 1024 * 1024 B petabyte P = 2**50 B = 1024 * 1024 * 1024 * 1024 * 1024 B exabyte E = 2**60 B = 1024 * 1024 * 1024 * 1024 * 1024 * 1024 B zettabyte Z = 2**70 B = 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 B yottabyte Y = 2**80 B = 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 B I have found this link to be quite useful: http://www.t1shopper.com/tools/calculate/ If you feel like a hard-drive manufacturer, you can start counting bytes by powers of 1000 (instead of the generous 1024). Just use bs => 1000. But if you are a floppy disk manufacturer and want to start counting in units of 1024000 (for your "1.44 MB" disks)? Then use bs => 1_024_000. If you feel like a purist academic, you can force the use of metric prefixes according to the Dec 1998 standard by the IEC. Never mind the units for base 1000 are (B, kB, MB, GB, TB, PB, EB, ZB, YB) and, even worse, the ones for base 1024 are (B, KiB, MiB, GiB, TiB, PiB, EiB, ZiB, YiB) with the horrible names: bytes, kibibytes, mebibytes, etc. All you have to do is to use si => 1. Aint that beautiful the SI system? Read about it: http://physics.nist.gov/cuu/Units/binary.html You can try a pure Perl "ls -lh"-inspired command with the one-liner, er, two-liner: $ perl -MNumber::Bytes::Human=format_bytes -e printf "%5s %sn", format_bytes(-s), $_ for @ARGV * Why to write such a module? Because if people can write such things in C, it can be written much easier in Perl and then reused, refactored, abused. And then, when it is much improved, some brave soul can port it back to C (if only for the warm feeling of painful programming).

Number::Bytes::Human is a Perl module that can ...

 
  • Perl Artistic
  • 9 Kb
  • 213
 
 

Review Number::Bytes::Human

  • captcha
 

Other software of Adriano R. Ferreira
  • Sort::Half::Maker  v.0.03Sort::Half::Maker is a Perl module to create half-sort subs easily. SYNOPSIS use Sort::Half::Maker qw(make_halfsort), $sub = make_halfsort( start => [ qw(x y z) ], end => [ qw(a b c) ], fallback => sub { $_[0] cmp $_[1] }, ), @list = sort ...
  • Tao::DBI::st  v.0.0008Tao::DBI::st is a Perl module for DBI statements with portable support for named placeholders. SYNOPSIS use Tao::DBI qw(dbi_connect dbi_prepare), $dbh = dbi_connect($args), $sql = q{UPDATE T set a = :a, b = :b where k = :k}, $stmt = ...

New Components & Libraries software
  • Generate Barcode Images in C#  v.2021.6.3IronBarcode can be utilized inside C#, VB.NET, ASP .NET, MVC, Web Services, Console and Desktop Applications. Requires .Net Framework 4.0, .NET Core 2.0 / 3.0, .NET Standard 2.0. https://ironsoftware.com/csharp/barcode/ ...
  • SentiVeillance SDK Trial  v.8.0.20210512Real-time biometric face recognition and pedestrian/vehicle tracking SDK for viodeo surveillance systems and networks. Automatic identification against watch list. Vehicle make and model estimation. Pedestrian mask, cloth and gender estimation.
  • The C# OCR Library  v.2021.2.1The Iron OCR library https://ironsoftware.com/csharp/ocr for C# developers provides advanced image to text functionality for microsoft.net web applications, desktop applications and enterprise services. Alternative to Tesseract 3, 4, 5 for C# VB .NET ...
  • VISCOM Video Capture Pro SDK ActiveX  v.14.0support IP Camera, web cam freehand drawing, Motion Detection , Capture Video from capture card, tv tuner, dv cam, dvd player to AVI or WMV 9, WMV8 file format.Draw multi overlay image, text on live video or save to video file.
  • Number Stamper  v.1.0Number Stamper 1.0 is an effective tool which adds searchable number stamps to PDF Documents. Common practice for legal case documents, bates numbering is useful for the organization of all types of document sets. Numbered pages allow you to track ...
  • Numberator  v.1.3.0.15Convert integers and currencies into words in 17 languages and 93 countries. Integers and currencies from clipboard: Copy any text with numbers into the clipboard and load it "from clipboard" to get a full translated list. Can generate a sequential ...