On 07/03/2012 16:18, mailing lists wrote:
Hello,
is there any way to extract the queued ID (7BC5A446) from the first
line and also match the second with only one regex??
#!/usr/bin/perl
use strict;
use warnings;
use 5.010;
while(<DATA>){
if
(/^(?<Month>\S+?)\s+?(?<Day>\S+?)\s+?(?<Time>\S+?)\s+?(?<Host>\S+?)\s+?(?<Program>\S+?):\s+?(?<QueueNumber>\S+?):\s+?to=(?<To>\S+?),\s+?relay=(?<relay>\S+?),\s+?delay=(?<delay>\S+?),\s+?delays=(?<delays>\S+?),\s+?dsn=(?<dsn>\S+?),\s+?status=(?<status>\S+?)\s+?(?<statusMsg>(?:queued
as (?<NextQueueID>.*))?.*)$/i) {
my $nextQueueID = $+{NextQueueID} || "None";
say "LineType: \"To\" 1: $+{Month} 2: $+{Day} 3: $+{Time} 4: $+{Host} 5:
$+{Program} 6: $+{QueueNumber} 7: $+{To} 8: $+{relay} 9: $+{delay} 10: $+{delays} 11: $+{dsn} 12:
$+{status} 13: $+{statusMsg} 14: $nextQueueID";
} else {
say "ERROR with line: ".$_
}
}
__DATA__
Mar 5 10:05:45 antispam3 postfix/smtp[1595]: 4CE0081:
to=<user...@example.com>, relay=clamav.example.com[1.1.1.1]:25, delay=0.31,
delays=0.14/0/0.01/0.16, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 7BC5A446)
Mar 5 10:06:37 antivir1 postfix/smtp[8193]: 7BC5A446:
to=<user...@example.com>, relay=mail.example.com[2.2.2.2]:25, delay=52,
delays=0.15/50/0.03/2.1, dsn=2.5.0, status=sent (250 2.5.0 Ok.)
What do you mean by "and also match the second"? This looks very much as
if you should be using split rather than a regex. There is certainly no
point in all the non-greedy matching - /\s+/ and /\S+/ will do fine.
Rob
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/