0
我有一個問題與Perl。我想解析一個電子郵件對象或記錄或文件。我想找到郵件來自哪裏。首先我必須檢查「x-envelope-from」行,如果不匹配,那麼我必須檢查「from」行。如何檢查字符串是否與perl中的正則表達式匹配?
這是我的一些示例文件:該文件
X-Envelope-From:
<[email protected]>
From: "=?iso-8859-9?B?RXYgVGH+/W1hY/1s/fD9bmRhIsdfyhjdbmRRmltIFNlem9u?=
=?iso-8859-9?B?dQ==?=" <[email protected]>
我的代碼打印2行:,兩個打印行,如果印刷在
[email protected]
[email protected]
鋤頭可以是可能的,並且ELSIF?檢查比賽時有問題嗎?
while ($line = <FILE>)
{
my ($from, $to, $spam_id, $date, $tmp_date, $m_day, $m_mon, $m_year, $m_hour, $m_min, $pos_tmp);
my ($subject);
#
if ($line =~ m/^(X-Envelope-From:).*/) {
if ($line =~ m/^X-Envelope-From:.*<(.*)>.*/) {
$from = $1;
}
else {
$line = <FILE>;
if ($line =~ m/.*<(.*)>.*/) {
$from = $1;
}
}
print $from . "\n";
}
elsif ($line =~ m/^(From:).*/) {
if ($line =~ m/^From:.*<(.*)>.*/) {
$from = $1;
}
else {
$line = <FILE>;
if ($line =~ m/.*<(.*)>.*/) {
$from = $1;
}
}
print $from . "\n";
}
}
在此先感謝。
有兩行輸出,因爲你必須輸入的兩行。對於第一行,「if」條件是真的(打印一個電子郵件地址),對於第二行,「elsif」條件是真的(它也打印一個電子郵件地址) – Gareth
是的抱歉我的錯誤,我修好了,但也有一些關於正則表達式的東西。謝謝 – kursat