vxp has asked for the wisdom of the Perl Monks concerning the following question:
So, upon finding "blah" it will replace it with "something". here's a test email that I fed into it:#!/usr/bin/perl use Mail::Internet; $msg = Mail::Internet->new([ <> ]); $to = $msg->get('To'); #$content = join( '',@{$msg->body} ); @content = @{$msg->body}; print "To: " . $to; foreach $line (@content) { @words = split(/ /, $line); foreach $word (@words) { if ($word =~ /blah/) { $word = "something"; } print "$word "; } }
and here's the resulting output:From root@val.vmsinfo.com Fri Dec 14 14:54:57 2007 Return-Path: <root@val.vmsinfo.com> X-Original-To: vxp Delivered-To: vxp@val.vmsinfo.com Received: by val.vmsinfo.com (Postfix, from userid 0) id 86A085FD705; Fri, 14 Dec 2007 14:54:57 -0500 (EST) To: vxp@val.vmsinfo.com Subject: hi Message-Id: <20071214195457.86A085FD705@val.vmsinfo.com> Date: Fri, 14 Dec 2007 14:54:57 -0500 (EST) From: root@val.vmsinfo.com (root) Status: O X-Status: X-Keywords: X-UID: 7 hi Val blah some more blah ..
Now, as you see, the "\n" before the second line was lost in the output: the ".." is now on the first line.. Any suggestions ? :)[vxp@val ~]$ ./mail.pl test.txt To: vxp@val.vmsinfo.com hi Val something some more something .. [vxp@val ~]$
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: A regex question
by moritz (Cardinal) on Jan 16, 2008 at 20:27 UTC | |
by johngg (Canon) on Jan 16, 2008 at 23:15 UTC | |
|
Re: A regex question
by amarquis (Curate) on Jan 16, 2008 at 20:26 UTC | |
|
Re: A regex question
by ww (Archbishop) on Jan 16, 2008 at 23:53 UTC | |
by vxp (Pilgrim) on Jan 17, 2008 at 00:17 UTC | |
|
Re: A regex question
by aquarium (Curate) on Jan 17, 2008 at 03:31 UTC |