2010年3月22日 星期一

Perl: Math::Round

Perl installation

  • Perl installation if it wasn't previously installed:
apt-get install perl
  • Perl Math Round library installation:
apt-get install libmath-round-perl
  • AppConfig and DBI perl modules installation:
apt-get install libappconfig-perl libdbi-perl


nearest TARGET, LIST

Rounds the number(s) to the nearest multiple of the target value. TARGET must be positive. In scalar context, returns a single value; in list context, returns a list of values. Numbers that are halfway between two multiples of the target will be rounded to infinity. For example:

  nearest(10, 44)    yields  40
nearest(10, 46)            50
nearest(10, 45)            50
nearest(25, 328)          325
nearest(.1, 4.567)          4.6
nearest(10, -45)          -50
===========================================
#!/usr/local/bin/perl
  use POSIX qw(ceil floor);

  $num = 42.4;  # The Answer to the Great Question (on a Pentium)!

  print "Floor returns: ", floor($num), "\n";
  print "Ceil returns:  ", ceil($num), "\n";

2010年3月15日 星期一

2010年3月14日 星期日

The Disk Usage Analyzer

[Screenshotdus.png]

Ubuntu: Checking folder size

In the target folder:
du -chks
Other: du -hs folderpath

2010年3月11日 星期四

Perl: Term::ANSIColor

print color("red"), "Text is red\n", color("reset"); print RED "Text is red\n", RESET;
  • Foreground colors
  •    30    Black
      31    Red
      32    Green
      33    Yellow
      34    Blue
      35    Magenta
      36    Cyan
      37    White
  • Background colors
  •    40    Black
      41    Red
      42    Green
      43    Yellow
      44    Blue
      45    Magenta
      46    Cyan
      47    White

2010年3月9日 星期二

Perl: Cross pl variable, hashtable, array

$ cat test.pl
use strict;

require "test2.pl";

our $variable;
print $variable;

$ cat test2.pl
our $variable = 42;

$perl test.pl
42

-------------------------
**
headers.pl
**
our @arr = ();
our $ht = {};
push($arr, "A");
$ht->{"A"} = "value";

**
main.pl
**
require "headers.pl";
our @arr;
our $ht;

print scalar(@arr)."\n";
print "$ht->{$arr[0]}";

2010年3月8日 星期一

ls如何只是輸出directory而不是file

ls如何只是輸出directory而不是file 不知道為什麼我的fbsd的ls -d 只是輸出"."?
ls如何只是輸出directory而不是file ls -ld */
ls如何只是輸出directory而不是file 好,比我的解決方案好多了: ls -lp | grep /
ls如何只是輸出directory而不是file ls -l|grep ^d
ls如何只是輸出directory而不是file ls -l | awk '$1 ~ /^d/ {print $9}' linux system
ls如何只是輸出directory而不是file --> ls -al | sed -n '/^d/p'
ls如何只是輸出directory而不是file 都不如頭一個解決方案好。
ls如何只是輸出directory而不是file [code]file *|grep directory[/code]
ls如何只是輸出directory而不是file --> 這個特別. 8)
ls如何只是輸出directory而不是file ls -d */
ls如何只是輸出directory而不是file ls -F |grep '\/$'
ls如何只是輸出directory而不是file 還是#ls -l |grep ^d 好,各個系統通用。

Ref: http://www.lslnet.com/linux/f/docs1/i30/big5237499.htm