projects
/
BackupPC.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
aff621b
)
added humanly readable unit (b k M G)
author
Dobrica Pavlinusic
<dpavlin@rot13.org>
Fri, 28 Jan 2011 13:48:14 +0000
(14:48 +0100)
committer
Dobrica Pavlinusic
<dpavlin@rot13.org>
Fri, 28 Jan 2011 13:48:14 +0000
(14:48 +0100)
lib/BackupPC/Search.pm
patch
|
blob
|
history
diff --git
a/lib/BackupPC/Search.pm
b/lib/BackupPC/Search.pm
index
479b51d
..
888a853
100644
(file)
--- a/
lib/BackupPC/Search.pm
+++ b/
lib/BackupPC/Search.pm
@@
-12,6
+12,10
@@
use XML::Writer;
use IO::File;
use Data::Dump qw(dump);
use IO::File;
use Data::Dump qw(dump);
+require Exporter;
+our @ISA=qw(Exporter);
+our @EXPORT=qw(unit);
+
my $on_page = 100;
my $pager_pages = 10;
my $on_page = 100;
my $pager_pages = 10;
@@
-1118,4
+1122,24
@@
sub displayGrid($) {
return $retHTML;
}
return $retHTML;
}
+my @units = qw/b k M G/;
+sub unit {
+ my $v = shift;
+
+ my $o = 0;
+
+ while ( ( $v / 10000 ) >= 1 ) {
+ $o++;
+ $v /= 1024;
+ }
+
+ if ( $v >= 1 ) {
+ return sprintf("%d%s", $v, $units[$o]);
+ } elsif ( $v == 0 ) {
+ return 0;
+ } else {
+ return sprintf("%.1f%s", $v, $units[$o]);
+ }
+}
+
1;
1;