4.1.6 單引號和雙引號的區別

先前提到:字串必須用單引號和雙引號括起來,那麼二者之間,有沒有什麼不同?

有! 至少有二個地方不一樣:

1. 跳脫符號在雙引號中才有效,在單引號中無效。

比如:

print "hello world\n";

出現 hello world 並且游標換至下一列


而 

print 'hello world\n';

出現 hello world\n 且游標沒有換行。

2. 雙引號中可以做變數代換,單引號則不行。

比如:

$hi="Hello";

print "$hi\n";

出現 Hello 並且游標換至下一列


而 

$hi="Hello";

print '$hi\n';


出現 $hi\n 且游標沒有換行。