From 15f531794b27b2be84b3f360ab1ccae236499ba0 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Fri, 2 Sep 2016 01:11:39 +0100 Subject: [PATCH] Bed --- etc/profile.d/functions | 7 +++++-- lib/perl/NB/Functions.pm | 8 +++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/etc/profile.d/functions b/etc/profile.d/functions index 2e94ff09..729c9ed5 100644 --- a/etc/profile.d/functions +++ b/etc/profile.d/functions @@ -156,7 +156,10 @@ bytes2h() { in="cat" [ -z "$@" ] || in="echo $@" - $in | perl -pe 'BEGIN{ + #use Number::Bytes::Human qw/&format_bytes/; + #s/$exp/bytes2h($1)/ge; + $in | perl -pe ' +BEGIN{ use NB::Functions qw/&bytes2h/; $exp = "([\\d\\.]+)"; if (@ARGV and $ARGV[0] =~ /regex=(\S+)/) { @@ -164,7 +167,7 @@ bytes2h() { $exp = $1; } }; -s/$exp/bytes2h($1)/ge; +0 and s/$exp/format_bytes($1)/ge ' $args } diff --git a/lib/perl/NB/Functions.pm b/lib/perl/NB/Functions.pm index e89eda02..0ae50bc6 100644 --- a/lib/perl/NB/Functions.pm +++ b/lib/perl/NB/Functions.pm @@ -280,9 +280,11 @@ sub bytes2h { if ($o >= 1099511627776) { return(sprintf('%.2fT',($o/1099511627776))); } # T elsif ($o >= 1073741824) { return(sprintf('%.2fG',($o/1073741824))); } # G + elsif ($o >= 1048576) { return(sprintf('%.1fM',($o/1048576))); } # M elsif ($o >= 1048576) { return(POSIX::ceil($o/1048576)."M"); } # M elsif ($o >= 1024) { return(POSIX::ceil($o/1024)."K"); } # K - else { return $o."bytes"; } +# NB 02.09.16 else { return $o."bytes"; } + else { return $o; } } @@ -436,9 +438,9 @@ sub db_connect { # NB 15.07.07 #------------------------------------------------------------------------------ # Bug if delete - NB 24.02.12 my $opt = shift @_; -my $opt = \%{$_[0]}; +my $opt = \%{$_[0]}; shift; my $iziopt; -my @dbi = @NB::Globals::DBI; +my @dbi = @_; require 'DBI.pm' unless $INC{'DBI.pm'}; -- 2.47.3