【发布时间】:2015-06-05 11:07:25
【问题描述】:
我有一个看起来像这样的字符串
Acanthocolla_cruciata,#8B5F65Acanthocyrta_haeckeli,#8B5F65Acanthometra_fusca,#8B5F65Acanthopeltis_japonica,#FFB5C5
我正在尝试添加新行,以便以列表格式添加。像这样
Acanthocolla_cruciata,#8B5F65
Acanthocyrta_haeckeli,#8B5F65
Acanthometra_fusca,#8B5F65
Acanthopeltis_japonica,#FFB5C5
我有一个 perl 脚本
use strict;
use warnings;
open my $new_tree_fh, '>', 'test_match.txt'
or die qq{Failed to open "update_color.txt" for output: $!\n};
open my $file, '<', $ARGV[0]
or die qq{Failed to open "$ARGV[0]" for input: $!\n};
while ( my $string = <$file> ) {
my $splitmessage = join ("\n", ($string =~ m/(.+)+\,+\#+\w{6}/gs));
print $new_tree_fh $splitmessage, "\n";
}
close $file;
close $new_tree_fh;
模式匹配有效,但它不会打印新行,因为我想制作列表。任何人都可以提出任何建议。
【问题讨论】:
-
我不确定您的模式匹配是否确实有效。您正在使用
(.+)的贪婪捕获,这会占用您的大部分字符串。