develooper Front page | perl.beginners | Postings from February 2002

Re: getting a block of text from file

Thread Previous
From:
Andrea Holstein
Date:
February 12, 2002 02:32
Subject:
Re: getting a block of text from file
Message ID:
pan.2002.02.12.11.32.36.350839.1558@yahoo.de
In article <OE63tSkrpEwwSm3olwR0000d1f2@hotmail.com> wrote "Chris Zampese" <czampese@hotmail.com>:

> Hi All,
>   I have a file that contains the contents of an email.  Its format is shown below...
> 
> (Lots of lines of random stuff)
> Content-Transfer-Encoding: quoted-printable
> 
> The message of the email is here then it is followed by
> 
> ------=_NextPart_000_0118_01C1B358.DE107900
> (lots more lines of stuff)
> 
> how would I get just the message into a variable (or array or whatever) so that I can use it?

One way could be to read the file until the nextpart-statement comes.
The snippet would read like:

my @email;
open EMAIL, "<filename" or die "Cannot open filename: $!";
while (<EMAIL>) {
	last if /NextPart/;
	push @email, $_;
}
close EMAIL;

Now, @email contains all lines before.

Best Wishes,
Andrea

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About