perl初心者BLOG

2009-05-31

[][]文字列の置き換えはs演算子 20:04

・サンプルコード

~$ cat hoge.pl
#!/usr/local/bin/perl

$msg = <<EOT;
HIs name is Mike.
Mike is student.
Mike live in UK.
EOT

$msg =~ s/Mike/Nancy/g;

print $msg, "\n";

・実行結果

~$ ./hoge.pl
HIs name is Nancy.
Nancy is student.
Nancy live in UK.