2016年9月17日 星期六

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"