root/lang/perl/autobox-Numeric-Bytes/trunk/sample/unitary @ 11293

Revision 11293, 490 bytes (checked in by hirose31, 5 years ago)

also accept "N.unit" format

2->daysに加えて、2.daysも受け付けるようにした。
">"がシェルでリダイレクトとして解釈されてうざいので。

  • Property svn:executable set to *
Line 
1#!/usr/bin/env perl
2use strict;
3use UNIVERSAL::require;
4die q{[usage]
5$ unitary '2->megabytes' '3.days'
62097152
7259200
8} if @ARGV == 0 || $ARGV[0] =~ /^--?h/;
9my @modules;
10for my $m qw(autobox autobox::Numeric::Bytes autobox::Numeric::Time) {
11    push @modules, $m if $m->require;
12}
13my $use = join '', map {"use $_; "} @modules;
14for (@ARGV) {
15    s/^(\d+(?:\.\d+)?)\.([a-zA-Z]+)$/$1->$2/; # transform N.unit to N->unit
16    my $e = "$use $_";
17    # warn $e."\n";
18    print eval($e), "\n";
19}
Note: See TracBrowser for help on using the browser.