Re: 想請教一下 perl 中的字串取代

看板Programming作者 (相見不如懷念)時間18年前 (2007/09/22 00:52), 編輯推噓0(005)
留言5則, 1人參與, 最新討論串9/12 (看更多)
※ 引述《kornelius (Kornelius)》之銘言: 不曉得你是否可以以下面的測資達到跟我一樣的輸出 my $str = 'a/bcde/f'; # 原始字串 my $pattern = '^a\/(.*)'; # 比對樣式 my $replace = 'c$1d'; # 取代字串 my $runtime = "\$str =~ s/$pattern/$replace/"; eval $runtime; print $str; 也就是 output 為 cbcde/fd 你使用的 double eval 方式能夠正確執行後面的 $replace 嗎 @@" -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.230.172.181

09/22 00:53, , 1F
另外我都是用Fedora跑的...
09/22 00:53, 1F

09/22 00:56, , 2F
突然覺得原本的測資好像就有錯...囧rz
09/22 00:56, 2F
※ 編輯: LiloHuang 來自: 61.230.172.181 (09/22 00:57)

09/22 00:57, , 3F
剛剛把pattern打成patern了 現在output
09/22 00:57, 3F

09/22 00:57, , 4F
已經改好了 還望說明~
09/22 00:57, 4F

09/22 00:59, , 5F
PS.現在的測資也是最先提問者要求的測資
09/22 00:59, 5F
文章代碼(AID): #16y_RO40 (Programming)
討論串 (同標題文章)
文章代碼(AID): #16y_RO40 (Programming)