$s = do{local $/; <>;}; print $s; # slurpモード
{local $/ = \3; local $\ = "\n"; print while <>;}
{local $\="\n";print "hello";print "hohoho";}
{local $" = "\t"; @a = ("a","b","c"); print "@a\n";}
$s = "a12b3c456de78"; @a = $s =~ /(\d+)/g; print "@a\n";
$s = "a12b3c456de78"; @a = ($s =~ /\d+/g); print "@a\n";
$s = "a12b3c456de78"; (my $t = $s) =~ s/\d/X/g; print "$t\n";
@list = grep(!$count{$_}++, @list);
$s = "abcde"; my ($r) = ($s =~ /X/, "defalut"); print "$r\n";
AND検索 :
$s = "and kensaku"; print "ok\n" if($s =~ /(?=.*d)(?=.*k)(?=.*an)/);
while(<>){print if (1..3) && /^\S/;}
($a == 1) && do {exit}
print_file(*FH); # ファイルハンドル渡し
タグの外側だけ置換 :
$s = "b<b>ba</b>"; $s =~ s/((?:\G|>)[^<]*?)b/$1X/g; print "$s\n";
マッチする位置 :
$s = "a12b3c456de78"; print pos($s),"\n" while $s =~ /(\d+)/g;
$s = "a12b3c456de78"; pos($s) = 10;
BEGIN {my $c = 0; sub count_up {++$c}} print count_up,"\n";
Closure
use Benchmark;
sanitize : ディレクトリトラバーサル、ヌル文字を削除
タイムアウトの設定 :
alarm(5); $SIG{ALRM}='tout'; 1 while(1); sub tout {die "time out\n"}
sub tout {print "hello\n"; alarm(5)}
パスワード直書きを避ける :
print "ok\n" if (crypt($pw, substr($e_pw,0,2)) eq $e_pw);