0

我想解析这组行,以便如果**<yagyavalkbhatt@yahoo.com>**在连续行中获得相同的模式,它应该在两者之间用“,”单独打印。

q2VDWKkY010407  2221878 Sat Mar 31 19:37 <Mailer-daemon>
                     (host map: lookup (my.local.domain): deferred)
                                             <yagyavalkbhatt@yahoo.com>
                                             <yagyavalkbhatt@yahoo.com>
q2VDWKkY010407  2221878 Sat Mar 31 19:37 <Mailer-daemon>
                     (host map: lookup (my.local.domain): deferred)
                                             <yagyavalkbhatt@yahoo.com>
                                             <yagyavalkbhatt@yahoo.com>

我怎样才能在 Perl 中做到这一点?

4

1 回答 1

2

环顾四周:

#!/usr/bin/env perl
use strict;
use warnings;

my $str = <<'EOS';
q2VDWKkY010407  2221878 Sat Mar 31 19:37 <Mailer-daemon>
                     (host map: lookup (my.local.domain): deferred)
                                             <yagyavalkbhatt@yahoo.com>
                                             <yagyavalkbhatt@yahoo.com>
q2VDWKkY010407  2221878 Sat Mar 31 19:37 <Mailer-daemon>
                     (host map: lookup (my.local.domain): deferred)
                                             <yagyavalkbhatt@yahoo.com>
                                             <yagyavalkbhatt@yahoo.com>
EOS

$str =~ s/(?<=<yagyavalkbhatt\@yahoo.com>)\s+(?=<yagyavalkbhatt\@yahoo.com>)/,/g;
print $str;

输出:

q2VDWKkY010407  2221878 Sat Mar 31 19:37 <Mailer-daemon>
                 (host map: lookup (my.local.domain): deferred)
                                         <yagyavalkbhatt@yahoo.com>,<yagyavalkbhatt@yahoo.com>
q2VDWKkY010407  2221878 Sat Mar 31 19:37 <Mailer-daemon>
                 (host map: lookup (my.local.domain): deferred)
                                         <yagyavalkbhatt@yahoo.com>,<yagyavalkbhatt@yahoo.com>
于 2012-06-04T06:37:11.987 回答