-3
我有一個文本文件,出現三次字符串'object'。每當它發生時用一個不同的字符串替換一個字符串
There is an object on the table
The object is under the chair
There might be an object in my pocket
我想要寫一個Perl腳本包含在三個元件的陣列另一個字符串來替換「對象」的每次出現。數組的第一個元素與第一次出現的「object」匹配,第二次出現的次數與第二次匹配,依此類推。
例如,如果
my @pattern = ("apple", "mango", "orange");
然後,輸出必須是:
There is an apple on the table
The mango is under the chair
There might be an orange in my pocket
您需要'shift @ pattern'而不是'pop'。 – Borodin
好點。我會編輯它。 – Sobrique
很好的答案和解釋... – ssr1012