まあ、それはあなたがデータで何をしたいかによって異なります。
これに大きな問題があると仮定すると、while (<>) { ... }
分割を使用するだけで最も簡単な解析を取得できます。
my @fields = split;
次のレベルは、少し意味を追加することです
my ($date, $time, $id, $host, $from, $to, undef, $dest) = split;
undef
(注:結果を無視する場合は、に割り当てることができます)
最後に、正規表現を使用することで、多くの不要な作業をクリーンアップできます。上記の分割を小さな正規表現と組み合わせて、各フィールドを個別にクリーニングすることもできます。
my ($datetime, $id, $host, $from, $to, $dest) =
/([\d-]+ [\d:]+) \s+ # date and time together
(\S+) \s+ # message id, just a block of non-whitespace
<(.*?)> \s+ # hostname in angle brackets, .*? is non-greedy slurp
\((.*?)\) \s+ # from email in parens
<(.*?)> \s+ # to email in angle brackets
\S+ \s+ # separated between to-email and dest
(\S+) # last bit, could be improved to (\w)=\[(.*?)\]
/x; # /x lets us break all of this up, so its a bit readable
もちろん、これをあらゆる種類のばかげたことに取り続けることができますが、これらのフィールドのより具体的な解析を開始する場合は、最初の分割に続いて分割フィールドの解析を行います。例えば:
my ($date, $time, ...) = split;
my ($year, $month, $day) = split(/-/, $date);
my ($hour, $min, $sec) = split(/:/, $time);
my ($from_user, $from_host) = ( $from =~ /< ([^\@]+) \@ (.*) >/x );
...etc...