in reply to is array the best way to handle this?

You mentioned a "series" of ASCII files, so I assume that we have one message per file. If so, how about the following? I'm using a hash, but only for convenience. Also, note that this is simply a rewriting of your inner while loop. I didn't add the rest as I was going for clarity.

#!/usr/bin/perl -w use strict; use Data::Dumper; my %message; while (defined (my $line = <DATA>)) { chomp $line; my ($field,$value) = $line =~ /^<([A-Z]+)>\s*(.*)/; $message{$field} = $value; # assumes message is last item in file and doesn't # start on same line as MESSAGE key if ('MESSAGE' eq $field) { $message{$field} = do { local $/; <DATA> }; } } print Dumper \%message; __DATA__ <SENDER> Sender Name <TO> To list <FROM> User Name <MESSAGE> Text text text tex

Cheers,
Ovid

New address of my CGI Course.

Replies are listed 'Best First'.
Re: Re: is array the best way to handle this?
by goosefairy (Novice) on Sep 08, 2003 at 19:52 UTC

    Thanks, this worked beautifully. One more question. This is an example of the text I get in the MESSAGE field:

    ^M
    ^M
    =================================================^M
    DT: AUGUST 7, 2003 ^M
    TO: ALL STATIONS / PROGRAM AND NEWS DIRECTORS ^M

    How in the world do I get rid of the ^M characters? They are carriage returns from something (I have no idea what). I have tried every regex replace I can think of but nada.

      Those are Windows carriage returns. s/\r//g; is the regex you're looking for.

      ------
      We are the carpenters and bricklayers of the Information Age.

      The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

      Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

        Thank you thank you thank you!!! That took care of the rest of it.

        goosefairy