■正規表現

マッチ演算子

パターンマッチ 意味
$a =~/照合パターン/ パターンマッチ
$a =~s/照合パターン/置換パターン 置換
$a =~tr/a-z/A-Z/ 変換

 

#!/bin/perl

$a = "This is a test";

$a =~s/test/Cat/;
print "$a\n";

$a =~tr/[a-z]/[A-Z]/;
print "$a\n";

$a =~s/\s//g;
print "$a\n";

実行結果

This is a Cat
THIS IS A CAT
THISISACAT