Perlについての質問箱 ..
[
2ch
|
▼Menu
]
■コピペモード
□
スレを通常表示
□
オプションモード
□このスレッドのURL
■項目テキスト
396:395 07/05/01 17:39:43 補足です。$textはファイルの内容、$regexpは置換前の文字列、$replaceは 置換後の文字列です。 397:デフォルトの名無しさん 07/05/01 17:51:02 >>395 ヒント: posと\G perl -e '$x = "aaaaaa"; pos($x) = 2; $x =~ s/\Ga/x/; print $x,"\n";' aaxaaa 398:395 07/05/01 21:09:08 ありがとうございます、無事できました。コードはこのようになりました。(たぶん問題ないはず…) $p = 0; while($text =~ /\G(?:.*\n)*?.*?($regexp)/gm) { $p = pos($text) - length($1); pos($text) = $p; if($all == 0) { $before = $1; $after = $1; $after =~ s/$regexp/$replace/m; print "置換前:\n$before\n置換後:\n$after\n"; do { print "置換する? [y]es [n]o [a]残り全て [g]キャンセル "; $key = <STDIN>; chomp($key); } while ($key ne "y" and $key ne "n" and $key ne "a" and $key ne "g"); if($key eq "y"){ $text =~ s/\G$regexp/$replace/m; pos($text) = $p + length($after); }elsif($key eq "n"){ pos($text) = $p + length($before); }elsif($key eq "a"){ $text =~ s/\G$regexp/$replace/gm; $all = 1; }else{ exit; } }elsif($all == 1) { $text =~ s/\G$regexp/$replace/gm; } }
次ページ
最新レス表示
スレッドの検索
類似スレ一覧
話題のニュース
おまかせリスト
▼オプションを表示
レスジャンプ
mixiチェック!
Twitterに投稿
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch
5384日前に更新/220 KB
担当:undef