HEX

Warning: set_time_limit() [function.set-time-limit]: Cannot set time limit - prohibited by configuration in /home/u547966/brikov.ru/www/wp-content/plugins/admin-menu-editor/menu-editor.php on line 745
Server: Apache
System: Linux 4.19.0-0.bpo.9-amd64 x86_64 at red40
User: u547966 (5490)
PHP: 5.3.29-mh2
Disabled: syslog, dl, popen, proc_open, proc_nice, proc_get_status, proc_close, proc_terminate, posix_mkfifo, chown, chgrp, accelerator_reset, opcache_reset, accelerator_get_status, opcache_get_status, pcntl_alarm, pcntl_fork, pcntl_waitpid, pcntl_wait, pcntl_wifexited, pcntl_wifstopped, pcntl_wifsignaled, pcntl_wifcontinued, pcntl_wexitstatus, pcntl_wtermsig, pcntl_wstopsig, pcntl_signal, pcntl_signal_dispatch, pcntl_get_last_error, pcntl_strerror, pcntl_sigprocmask, pcntl_sigwaitinfo, pcntl_sigtimedwait, pcntl_exec, pcntl_getpriority, pcntl_setpriority
Upload Files
File: //usr/share/doc/libmath-calc-units-perl/examples/ucalc
#!/usr/bin/perl
use Getopt::Long;
use File::Basename qw(basename);
use Math::Calc::Units qw(convert readable calc);

use strict;
use warnings;

sub usage {
    my ($msg, $bad) = @_;
    my $out = $bad ? *STDERR : *STDOUT;

    my $CMD = basename($0);
    if ($msg) {
	print $out "$CMD: $msg\n";
    }

    print $out <<"END";
usage:

Calculate the given expression, and guess human-readable units for the result:
    $CMD [-v] [-a] <expr>

Convert the given expression to the requested units:
    $CMD -c <expr> <unit>
    $CMD --convert <expr> <unit>

Examples:
How long does it take to download 10MB over a 384 kilobit/sec connection?
    $CMD "10MB / 384Kbps"

What is the expected I/O rate for 8KB reads on a disk that reads at 20MB/sec
and has an average seek time of 15ms?
    $CMD "8KB / (8KB/(20MB/sec) + 15ms)"

Or if you prefer to calculate that by figuring out the number of seconds
per byte and inverting:
    $CMD "((1sec/20MB) + 15ms/8KB) ** -1"

How many gigabytes can you transfer in a week at 2MB/sec?
    $CMD -c "2MB/sec" "GB/week"

How many angels fit on the heads of 17 pins (with some assumptions)?
(This demonstrates that unknown units are allowed, with plurals.)
    $CMD "42 angels/pinhead * 17 pinheads"
END

    exit($bad ? 1 : 0);
}

my $verbose = 0;
my $abbreviate = 0;
my $action = 'readable';

GetOptions("verbose|v!" => \$verbose,
           "abbreviate|abbrev|a" => \$abbreviate,
           "convert|c!" => sub { $action = 'convert' },
           "help|h!" => sub { usage("", 0) },
          )
  or usage("invalid arguments", 1);

if ($action eq 'convert') {
    usage("not enough args", 1) if (@ARGV < 2);
    usage("too many args", 1) if (@ARGV > 2);
    my ($expr, $units) = @ARGV;
    if ($units =~ /^\s*\d+/) {
      warn("WARNING: Destination units in conversion should probably not have a value\n");
    }
    print convert($expr, $units), "\n";
} elsif ($action eq 'readable') {
    usage("", 0) if @ARGV == 0;
    usage("too many ARGV", 1) if (@ARGV > 1);
    print "$_\n" foreach readable($ARGV[0], verbose => $verbose, abbreviate => $abbreviate);
}

1;