删除perl中包含重复正则表达式的行
我有一个包含以下元素的数组:
@array = qw/ john jim rocky hosanna/;
INPUT FILE:
john wears blue shirt
hosanna knows drawing
george and jim went to europe
john went to swimming
jim wears yellow shirt
rocky went to swimming
rocky learns painting
hosanna learns painting
REQUIRED OUTPUT:
john wears blue shirt
hosanna knows drawing
george and jim went to europe
rocky went to swimming
所以,我只需要第一次出现的行。
I have an array that contains elements like:
@array = qw/ john jim rocky hosanna/;
INPUT FILE:
john wears blue shirt
hosanna knows drawing
george and jim went to europe
john went to swimming
jim wears yellow shirt
rocky went to swimming
rocky learns painting
hosanna learns painting
REQUIRED OUTPUT:
john wears blue shirt
hosanna knows drawing
george and jim went to europe
rocky went to swimming
so, I need to have only first occurrences lines.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
希望这有效+
hope this works +
制作另一个数组来指示该名称是否已被使用怎么样?然后,当您第一次阅读 Jim 的行时,请将此数组中的变量设置为所使用的并写入输出中。如果过去已经使用过,则无需执行任何操作。
What about making another array which indicates if the name was already used? Then, first time you read line with Jim, set variable in this array as used and write in into output. If it was already used in the past, do nothing.
单程。我将数组数据保存到哈希中,并在输入文件中找到条目时删除该条目。
script.pl 的内容:
命令:
输出:
One way. I save array data to a hash and delete an entry when found in the input file.
Content of
script.pl
:Command:
Output: