如何用文件中的另一个元素替换一个数组元素 [英] How to replace one array element with another element in a file

查看:135
本文介绍了如何用文件中的另一个元素替换一个数组元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我无法用文件中的相应array2元素替换所有array1元素.这是我的代码

Hi,

I am unable to replace all the array1 elements with corresponding array2 elements in a file. Here is my code

open FILE1, "<Test3.txt" or die " Cannot open to write file!";
my @newlines;
while (<FILE1>)
{
 chomp($_);
 $_ =~ s/@array1/@array2/g;
 push(@newlines,$_);
} 
close FILE1;


但是,每个数组元素都将单独替换..
我也尝试过使用for循环,但是没有用.请帮忙.


在此先感谢,


However, each array element is getting replaced individually..
I tried using for loop also, but didn''t work. Please help.


Thanks in Advance,

推荐答案

_ );
_);


_ =〜s/@ array1/@ array2/g; push( @ newlines
_ =~ s/@array1/@array2/g; push(@newlines,


_ )); } 关闭FILE1;
_); } close FILE1;


但是,每个数组元素都将单独替换..
我也尝试过使用for循环,但是没有用.请帮忙.


在此先感谢,


However, each array element is getting replaced individually..
I tried using for loop also, but didn''t work. Please help.


Thanks in Advance,


这篇关于如何用文件中的另一个元素替换一个数组元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆