#!/usr/bin/perl #H# takes a number of bytes as an argument and splits it into several different #H# binary computer notations. if ($ARGV[0] eq "") { # If no args take num of bytes from stdin $Bytes=<>; } else { # If args take arg as num of bytes $Bytes=$ARGV[0]; } chomp $Bytes; $Bytes =~ s/ //g; $Bytes =~ s/\t//g; # Print usage info if arg not a number if ($Bytes =~ /\D+/) { print "Byte version 1.0 Written by Kevin Korb \n"; print "Converts bytes into KB, MB, and GB\n"; print "Usage:\n"; print "byte [number of bytes]\n"; print "or\n"; die "[some program that outputs bytes] | byte\n"; } $KBytes=$Bytes/1024; $MBytes=$KBytes/1024; $GBytes=$MBytes/1024; $TBytes=$GBytes/1024; #$TBytes=$GBytes/1024; printf ("%26.0f Bytes\n",$Bytes); printf ("%30.3f KBytes\n",$KBytes); printf ("%30.3f MBytes\n",$MBytes); printf ("%30.3f GBytes\n",$GBytes); printf ("%30.3f TBytes\n",$TBytes); #printf ("%30.3f TBytes\n",$TBytes);