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

Re: getting a block of text from file

Thread Previous
Andrea Holstein
February 12, 2002 02:32
Re: getting a block of text from file
Message ID:
In article <> wrote "Chris Zampese" <>:

> 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,

Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About