| 網路管理語言 Perl 入門與實作: | ||
|---|---|---|
| <<< Previous | 4. Perl 的資料型態 | Next >>> |
Perl 的引號寫法多種:括號均可任意換成其它符號。
1. 單引號:q
$target = q[This is what you have];
同於
$target = 'This is what you have';
2. 雙引號:qq
$target = qq[This is what you have];
同於
$target = "This is what you have";
3. 執行符:qx
$run = qx[ls -la];
同於
$run = `ls -la`;
4. 串列:qw
@str = qw( ABC EDF XYZ 123 );
同於
@str = ("ABC", "EDF", "XYZ", "123");
同於
@str = split(/ /, q/ABC EDF XYZ 123/);
5. 正規表示式:qr
foreach $pattern (@patterns) {
$reg = qr/$pattern/;
foreach $line (@lines) {
print "$line 符合" if ($line =~ /$reg/);
}
}
|
| <<< Previous | Home | Next >>> |
| 4.5 變數的範圍 | Up | 4.7 使用預設值 |