[HRPM] an actual question!

Christopher Hicks chicks at chicks.net
Thu May 23 21:43:33 CDT 2002


On Thu, 23 May 2002, Mike Patten wrote:
> If I'm not mistaken, there are no blank lines in the header and a blank
> line separates the header from the body. Assuming that's the case and
> that the file only contains one piece of e-mail, this should read the
> file from STDIN or a file specified on the command line and print the
> body of the message to STDOUT.
>
> #!/usr/bin/perl -w
>
> use strict;
>
> my $body = 0;
> while (<>) {
>     if ($body) {
>         print;
>     } elsif ( m/^\s*$/ ) {  # if the line contains nothing except
> (maybe) whitespace,
>         $body = 1;          # the body comes next
>     }
> }

TMTOWTDI.

If memory isn't a concern:

#!/usr/bin/perl -w

use strict;

my $emailfile = shift @ARGV;

open(IN,$emailfile) or die "couldn't open $emailfile ($!)";
my $contents = join('',<IN>);
close(IN);

$contents =~ s/^.*?\n\n//s;

$emailfile .= '.out';

open(OUT,">$emailfile") or die "couldn't open $emailfile ($!)";
print OUT $contents;
close(OUT);

-- 
</chris>

There are two ways of constructing a software design. One way is to make
it so simple that there are obviously no deficiencies. And the other way
is to make it so complicated that there are no obvious deficiencies.
                                                        - - C.A.R. Hoare




More information about the Norfolk-pm mailing list