Thread View: best.unix
7 messages
7 total messages
Started by lordbear
Thu, 12 Nov 1998 00:00
Perl Q: parsing mail messages
Author: lordbear
Date: Thu, 12 Nov 1998 00:00
Date: Thu, 12 Nov 1998 00:00
39 lines
2088 bytes
2088 bytes
So, I want to be able to forward an email message containing useful
information and have it parsed (via a Perl CGI) into a ASCII DB.
I've writtent the first part of the script, which strips headers
and other extraneous info. Now I am left with:
//////////////////////////////////////////
perquisite \PURR-kwuh-zit\ (noun)
*1 : a privilege, gain, or profit incidental to regular salary
or wages; especially : one expected or promised
2 : gratuity, tip
3 : something held or claimed as an exclusive right or
possession
|Example sentence:
Joanne's new job is loaded with perquisites, including
unlimited use of the company car and credit card and access
to the corporate health center.
/////////////////////////////////////////
Note the blank lines at the head and tail.
Objective: Have the first line of text appear as one 'field', the
following paragraph as the second and the next block of text as the
third, stripping away the extra speaces that indent lines, etc.
I'm having a devil of a tmie with the necessary regexps and the right
method for reading through and parsing the file.
Any ideas appreciated!
Bear
-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-
Don 'Bear' Wilkinson San Francisco / Daly City bear@lair.org
Computer support professional seeking full-time employment;
review my resume and interests at http://www.lair.org/bear/work.html
Re: Perl Q: parsing mail messages
Author: Dave W. Smith
Date: Fri, 13 Nov 1998 00:00
Date: Fri, 13 Nov 1998 00:00
53 lines
2455 bytes
2455 bytes
lordbear@best.com wrote: > So, I want to be able to forward an email message containing useful > information and have it parsed (via a Perl CGI) into a ASCII DB. > I've writtent the first part of the script, which strips headers > and other extraneous info. Now I am left with: > ////////////////////////////////////////// > perquisite \PURR-kwuh-zit\ (noun) > *1 : a privilege, gain, or profit incidental to regular salary > or wages; especially : one expected or promised > 2 : gratuity, tip > 3 : something held or claimed as an exclusive right or > possession > |Example sentence: > Joanne's new job is loaded with perquisites, including > unlimited use of the company car and credit card and access > to the corporate health center. > ///////////////////////////////////////// > Note the blank lines at the head and tail. > Objective: Have the first line of text appear as one 'field', the > following paragraph as the second and the next block of text as the > third, stripping away the extra speaces that indent lines, etc. > I'm having a devil of a tmie with the necessary regexps and the right > method for reading through and parsing the file. > Any ideas appreciated! Something like the following should get you closer to what you're looking for. # ignoring the initial and trailing blank line, separate # $_ into a first line, a second paragraph, and a third # paragraph ($first,$second,$third) = /^\n(.*?\n)(.*?\n)\n(.*)\n$/s; # unindent the second paragraph $second =~ s/^\s+//; $second =~ s/\n\s+/\n/sg; # unindent the third paragraph $third =~ s/^\s+//; $third =~ s/\n\s+/\n/sg; Dave ____________________________________________________________________________ Dave W. Smith mailto:dws@best.com http://www.best.com/~dws
Re: Perl Q: parsing mail messages
Author: lordbear
Date: Mon, 16 Nov 1998 00:00
Date: Mon, 16 Nov 1998 00:00
84 lines
3914 bytes
3914 bytes
Dave W. Smith <dws@shell3.ba.best.com> wrote:
> lordbear@best.com wrote:
>> So, I want to be able to forward an email message containing useful
>> information and have it parsed (via a Perl CGI) into a ASCII DB.
>> I've writtent the first part of the script, which strips headers
>> and other extraneous info. Now I am left with:
>> //////////////////////////////////////////
>> perquisite \PURR-kwuh-zit\ (noun)
>> *1 : a privilege, gain, or profit incidental to regular salary
>> or wages; especially : one expected or promised
>> 2 : gratuity, tip
>> 3 : something held or claimed as an exclusive right or
>> possession
>> |Example sentence:
>> Joanne's new job is loaded with perquisites, including
>> unlimited use of the company car and credit card and access
>> to the corporate health center.
>> /////////////////////////////////////////
>> Note the blank lines at the head and tail.
>> Objective: Have the first line of text appear as one 'field', the
>> following paragraph as the second and the next block of text as the
>> third, stripping away the extra speaces that indent lines, etc.
>> I'm having a devil of a tmie with the necessary regexps and the right
>> method for reading through and parsing the file.
>> Any ideas appreciated!
> Something like the following should get you closer to what you're
> looking for.
> # ignoring the initial and trailing blank line, separate
> # $_ into a first line, a second paragraph, and a third
> # paragraph
> ($first,$second,$third) = /^\n(.*?\n)(.*?\n)\n(.*)\n$/s;
> # unindent the second paragraph
> $second =~ s/^\s+//;
> $second =~ s/\n\s+/\n/sg;
> # unindent the third paragraph
> $third =~ s/^\s+//;
> $third =~ s/\n\s+/\n/sg;
Thanks for the hints, Dave!
Let's see if I understand this and can therefore translate into
human-readable English... please correct me if needed. :)
> # ignoring the initial and trailing blank line, separate
> # $_ into a first line, a second paragraph, and a third
> # paragraph
> ($first,$second,$third) = /^\n(.*?\n)(.*?\n)\n(.*)\n$/s;
Beginning at the first character, match (and ignore) the immediately
following newline character. The first grouping contains any number of
characters up to a newline. [What does the '?' do?] The second grouping
follows the same rules. The third matches the rest of the characters up to
the end newline.
Now, my question is; how is it that this would work as there are
intervening newlines in the respective paragraphs? I was trying to
compose a regexp that would detect two adjacent newlines and therefore
assume it had found the blank line between paragraphs. I see no such
interpolation here, unless that's how the question mark works. :)
Thanbks gain, in advance, for insight and illumination!
Bear
--
-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-
Don 'Bear' Wilkinson San Francisco / Daly City bear@lair.org
Computer support professional seeking full-time employment;
review my resume and interests at http://www.lair.org/bear/work.html
Re: Perl Q: parsing mail messages
Author: Dave W. Smith
Date: Mon, 16 Nov 1998 00:00
Date: Mon, 16 Nov 1998 00:00
31 lines
2176 bytes
2176 bytes
lordbear@NOSPAMbest.com wrote: > Let's see if I understand this and can therefore translate into > human-readable English... please correct me if needed. :) >> # ignoring the initial and trailing blank line, separate >> # $_ into a first line, a second paragraph, and a third >> # paragraph >> ($first,$second,$third) = /^\n(.*?\n)(.*?\n)\n(.*)\n$/s; > Beginning at the first character, match (and ignore) the immediately > following newline character. The first grouping contains any number of > characters up to a newline. [What does the '?' do?] The second grouping > follows the same rules. The third matches the rest of the characters up to > the end newline. Correct. The '?' modifies the previous "atom" (.*) to match as few instances as possible. This guarantees that '(.*?\n)\n' will match up to (and including) the first blank line. > Now, my question is; how is it that this would work as there are > intervening newlines in the respective paragraphs? I was trying to > compose a regexp that would detect two adjacent newlines and therefore > assume it had found the blank line between paragraphs. I see no ) > interpolation here, unless that's how the question mark works. :) $third may contain multiple paragraphs, if that's what you're asking. You can use the same technique to break those paragraphs apart. Dave ____________________________________________________________________________ Dave W. Smith mailto:dws@best.com http://www.best.com/~dws
Re: Perl Q: parsing mail messages
Author: lordbear
Date: Mon, 16 Nov 1998 00:00
Date: Mon, 16 Nov 1998 00:00
55 lines
3361 bytes
3361 bytes
Dave W. Smith <dws@shell3.ba.best.com> wrote:
> lordbear@NOSPAMbest.com wrote:
>> Let's see if I understand this and can therefore translate into
>> human-readable English... please correct me if needed. :)
>>> # ignoring the initial and trailing blank line, separate
>>> # $_ into a first line, a second paragraph, and a third
>>> # paragraph
>>> ($first,$second,$third) = /^\n(.*?\n)(.*?\n)\n(.*)\n$/s;
>> Beginning at the first character, match (and ignore) the immediately
>> following newline character. The first grouping contains any number of
>> characters up to a newline. [What does the '?' do?] The second grouping
>> follows the same rules. The third matches the rest of the characters up to
>> the end newline.
> Correct. The '?' modifies the previous "atom" (.*) to match
> as few instances as possible. This guarantees that '(.*?\n)\n'
> will match up to (and including) the first blank line.
Based on my obviously mistaken understanding of such things, I would
expect that the '?' would have to trail the '\n' in order to pick
up multiple lines before a blank line. e.g., '(.*\n?)\n'
I think this because I believe that since each line has a newline at the
end, that newline has to be included within the match conditions.
I guess I get fuzzy at the 'breakpoints' with regexps; when is a match
'entity' complete? The 'atom' plus quantitative modifiers? And so on.
Of course, I don't even fully understand the use of parentheses.
(sigh) So much to learn :)
Bear
>> Now, my question is; how is it that this would work as there are
>> intervening newlines in the respective paragraphs? I was trying to
>> compose a regexp that would detect two adjacent newlines and therefore
>> assume it had found the blank line between paragraphs. I see no )
>> interpolation here, unless that's how the question mark works. :)
> $third may contain multiple paragraphs, if that's what you're asking.
> You can use the same technique to break those paragraphs apart.
I was trying to express that I was concerned about the fact that
each line contains a newline at the end. Therefore, I didn't know
how to tell it to 'match until a newline is followed immediately by
another newline.' I was going for something like (.*\n)\n.
Bear
--
-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-
Don 'Bear' Wilkinson San Francisco / Daly City bear@lair.org
Computer support professional seeking full-time employment;
review my resume and interests at http://www.lair.org/bear/work.html
Re: Perl Q: parsing mail messages
Author: Smith and O'Halloran
Date: Fri, 20 Nov 1998 00:00
Date: Fri, 20 Nov 1998 00:00
27 lines
1883 bytes
1883 bytes
In article <36506b2a$0$12761@nntp1.ba.best.com>, >> Correct. The '?' modifies the previous "atom" (.*) to match >> as few instances as possible. This guarantees that '(.*?\n)\n' >> will match up to (and including) the first blank line. > >Based on my obviously mistaken understanding of such things, I would >expect that the '?' would have to trail the '\n' in order to pick >up multiple lines before a blank line. e.g., '(.*\n?)\n' Sounds like you may have been using the original camel book as a reference (the one that describes perl version 4). The magic with "?" after "*" came with perl version 5. /x(.*)\n(.*)/ = match "x" and then the maximum number of characters that leaves a newline left over. If the string has multiple newlines, they get matched as well. This puts everything after "x" (including the embedded newlines) into $1, leaving $2 = "". /x(.*)?\n(.*)/ = match "x" and then do a non-greedy match of any number of characters, stopping at the first newline. In this case, $1 gets just one line, $2 gets all the rest. -Joe -- INWAP.COM is Joe and Sally Smith, John and Chris O'Halloran and our cats See http://www.inwap.com/ for PDP-10, "ReBoot", "Shadow Raiders"/"War Planets"
Re: Perl Q: parsing mail messages
Author: lordbear
Date: Sat, 21 Nov 1998 00:00
Date: Sat, 21 Nov 1998 00:00
38 lines
2438 bytes
2438 bytes
Smith and O'Halloran <inwap@best.com> wrote:
> In article <36506b2a$0$12761@nntp1.ba.best.com>,
>>> Correct. The '?' modifies the previous "atom" (.*) to match
>>> as few instances as possible. This guarantees that '(.*?\n)\n'
>>> will match up to (and including) the first blank line.
>>
>>Based on my obviously mistaken understanding of such things, I would
>>expect that the '?' would have to trail the '\n' in order to pick
>>up multiple lines before a blank line. e.g., '(.*\n?)\n'
> Sounds like you may have been using the original camel book as a
> reference (the one that describes perl version 4). The magic with
> "?" after "*" came with perl version 5.
Are you clairvoyant, too? :)
> /x(.*)\n(.*)/ = match "x" and then the maximum number of characters
> that leaves a newline left over. If the string has
> multiple newlines, they get matched as well. This
> puts everything after "x" (including the embedded
> newlines) into $1, leaving $2 = "".
> /x(.*)?\n(.*)/ = match "x" and then do a non-greedy match of any number
> of characters, stopping at the first newline.
> In this case, $1 gets just one line, $2 gets all the rest.
All I can say is: Wow.
Just when one thinks they know even a little, they are reminded of just
little they even can understand. :0
Thanks!!! for your help (everyone).
Bear
-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-=+=-
Don 'Bear' Wilkinson San Francisco / Daly City bear@lair.org
Computer support professional seeking full-time employment;
review my resume and interests at http://www.lair.org/bear/work.html
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads