[CMI.PM] String matching sanity check?
Daniel S. Lewart
lewart at uiuc.edu
Wed May 25 16:01:37 PDT 2005
Mitch,
> Now, I've discovered several continued lines. Any suggestions on how to
> handle things like this cleanly:
> Subject: DAST: Iperf - read failed: Connection refused -
> luca.seoli at aliceposta.it
> Mime-Version: 1.0
How do I parse a mail header?:
http://perldoc.perl.org/perlfaq9.html#How-do-I-parse-a-mail-header%3f
> (I want to check for an email address anywhere between the Subject: line
> and the next "real" line, the Mime-Version: line.)
> Theoretically, this:
> #!/usr/bin/perl -p0777i.old
> s/Subject: (.*)@(.*)Mime-Version:/Subject: \1 --at-- \2Mime-Version:/s;
> or this:
> #!/usr/bin/perl -p0777i.old
> s/Subject: (.*)@(.*)Mime-Version:/Subject: \1 --at-- \2Mime-Version:/m;
> should work, right? But I'm clearly not understanding something correctly,
> because they don't work.
Since they don't work in practice, they shouldn't work theoretically either.
> The -p0777 says to look at the whole file, not just line-by-line, so why is
> this not matching?
For starters, I would change the first line to:
#!/usr/bin/perl -W -0777 -p -i.old
Then I would change \1 and \2 to $1 and $2, respectively.
Perhaps you want /s instead of /m?
Good luck!
Dan
More information about the Champaign-Urbana
mailing list