perl regex

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Trent Shipley
Date:  
Subject: perl regex
On Wednesday 2003-03-26 14:05, David A. Sinck wrote:
> \_ SMTP quoth Trent Shipley on 3/26/2003 13:33 as having spake thusly:
> \_
> \_  [very well explained answer]
> \_
> \_ my $first_datum      = m/$first_separator
> \_                                     [^:]
> \_                                     $middle_separator
> \_                                     /x;
> \_ my $middle_datum  = m/$middle_separator
> \_                                     [^:]
> \_                                     $middle_separator
> \_                                     /x;
> \_ my $last_datum     = m/$middle_separator
> \_                                     [^:]
> \_                                     \Z
> \_                                     /x;

>
> The only gotcha is that this assumes that there are but three fields.
>
> David


I assumed no such thing.

The overall logic (that I left out [oops]) was:

#####################

WHILE there is a next line, get it;

WHILE the line is not the empty string

if first_datum found, then put it in some data structure (an array of hashes
or array-of-arrays might be appropriate) elsif middle_datum, elsif
end_dataum.

# If going line-by-line process the data here.
# nb, you might want to case-select for middle_datum in the first test for
efficiency at the expenese of readability.

Throw away all the text you just matched.
# If you wrote the code right the string gets shorter with each pass; hence,
finite loop.

= pod
This can be done with

use English; with $PREMATCH, $MATCH, $POSTMATCH
or
$1, $2 etc.

But for efficiency it is better to use pos() and substr() or \G.
= cut

END-WHILE # got fields for this record
END-WHILE # got the records in this "file"