2016年9月17日 星期六

perl quotes

Alternative Quotes: qq, q, qw, qx

print qq/Hello\n/;                  # same as: print "Hello\n";
print q/He owes $5.00/;       #  same as: print 'He owes $5.00', "\n";
@states=qw( E T A L );       # same as ("E", "T", "A","L")
$today = qx(date);               # same as $today = 'date'; 



While we usually think of quotes as literal values,
in Perl they function as operators,
providing various kinds of interpolating and pattern matching capabilities.
Perl provides customary quote characters for these behaviors,
but also provides a way for you to choose your quote character for any of them.
In the following table, a "{}" represents any pair of delimiters you choose.

Customary  Generic        Meaning        Interpolates
                 ''       q{}          Literal             no
               ""      qq{}          Literal             yes
               ``      qx{}          Command             yes*
                        qw{}         Word list            no
                //       m{}       Pattern match          yes*
                         qr{}          Pattern             yes*
                         s{}{}      Substitution          yes*
                         tr{}{}    Transliteration         no (but see below)
              <<EOF                 here-doc            yes*

    * unless the delimiter is ''.



perl operators and precedence


operators
+
-
*
/

precedence
4+2*4
(4+2)*4

notice:  ++ different location different result
print $num1++ . "\n";
result: 10

print $num1;
11

print ++$num2 . "\n";
11



$letter  = "a";
$letter++;
print  "$letter\n";





perl conditionals

loop,foreach

if elsif else

unless

perl arrays

array

push

pop

shift

merge

reverse

sort

qw



perl variables

$a = 1;

($a , $b) = (1,2);

$c = $a + $b ;

print "$a\n";
print "$b\n";
result: 1 2

print "$c\n";
result: 3

notice:
print "$a + $b \n";
result: 1 + 2

$str = "Hello Wrold!\n";
print "$str\n";
result: Hello World!


my $name = 'Foo';
print 'Hello $name, how are you?\n';
Single quoted result:  Hello $name, how are you?\n

print "Hello $name, how are you?\n";
Double quoted result:  Hello Foo, how are you?



notice:
$name = 'Foo'; the same as $name = "Foo";
\  在許多程式語言解釋為跳脫字元。
\n 在許多程式語言解釋為換行字元。
quoted裡的元件基本上會當作字串處理,包含實際字串和便數字串。所以 print "$string"可以,但是如果是print "$strint++\n"就不行。要使用print $sting++."\n"


perl basics

1. 由shebang (#!) 開始

#!/usr/bin/perl

類 Unix 作業系統的程式載入器會分析 Shebang 後的內容,將這些內容作為直譯器指令,並呼叫該指令,並將載有 Shebang 的檔案路徑作為該直譯器的參數。


 2. 以browser呼叫執行傳回最少要加上

print "Content-Type: text/html; charset=\"UTF-8\"\n\n";


3. exit;


example code:

#!/usr/bin/perl

print "Content-Type: text/html; charset=\"UTF-8\"\n\n";

print "Hello World!\n";

exit;

result:

Hello World !

2016年9月16日 星期五

mysql to mariaDB(before version 10)

1. 安裝 MariaDB。你的MySQL所有工具,連接程式都可以如常運作。你也不需要匯出和匯入資料。

格式與檔案名稱都是相同的。

2. 所有客戶端的API、協議和結構都是相同的;

3. 所有文件件​​名、二進製文件、路徑、端口、套接字等……全都是一樣的;

4. 所有的MySQL與其他語言(PHP、Perl、Python、Java、.NET、MyODBC、Rub、MySQL C..)

的連接文件無需任何改動,在MariaDB就可工作;


MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能輕鬆成為MySQL的代替品。

在存儲引擎方面,10.0.9版起使用XtraDB(名稱代號為Aria)來代替MySQL的InnoDB。


版本方面,MariaDB直到5.5版本,均依照MySQL的版本。

因此,使用MariaDB5.5的人會從MySQL 5.5中了解到MariaDB的所有功能。

從2012年11月12日起發布的10.0.0版開始,不再依照MySQL的版號。

10.0.x版以5.5版為基礎,加上移植自MySQL 5.6版的功能和自行開發的新功能。


相對於最新的MySQL5.6,MariaDB在性能、功能、管理、NoSQL擴展方面包含了更豐富的特性。

比如微秒的支持、線程池、子查詢優化、組提交、進度報告等。