> -----Original Message-----
> From: David Draley [mailto:[EMAIL PROTECTED]]
> Sent: September 20, 2001 12:35
> To: [EMAIL PROTECTED]
> Subject: reg exp
> 
> hello -
> 
> I am trying to search a <file> for any sentence that ends in "." or "?"  I 
> want to only print those sentences that end with "." or "?" I am having 
> trouble with the reg expression syntax...
> 
> ------------------
> 
> while (<file>)
>     {
> $file=<file>;
>        if(/\.\?$/){
>          print "$only_sentences_that_end_with_._or_?";
>       }
>     }

David,

You have what could be an extraordinarily difficult problem.  If you meant "print only 
lines from
the file that end with a period or question mark, then what you want is fairly simple:

    while (<DATA>) {
        print if /[.?]$/;
    }
    __DATA__
    This is a test.
    Is this another test?
    This doesn't print!

However, you said "sentences".  If that is the case, you're going to stumble on things 
like:

    "How do I get all the blood off the toys?" demanded Joan!

(Let's just ignore how terribly that's written)

How exactly would you want to parse that?  Do you consider the part in quotes part of 
the
sentence, or is the entire construct part of the sentence.  The construct ends in an 
exclamation
point, so it doesn't fit your criteria.

In short, you have a difficult question.  Here's how to get a better answer:

1.  Provide some sample data with several test cases that provide different results.
2.  Provide the rules against which you wish to analyze the data (don't forget to take 
into
account whether or not a "sentence" in your input data could span multiple lines).
3.  Provide the expected output derived from the rules, once run against the sample 
data.

Cheers,
Curtis "Ovid" Poe

=====
Senior Programmer
Onsite! Technology (http://www.onsitetech.com/)
"Ovid" on http://www.perlmonks.org/

__________________________________________________
Terrorist Attacks on U.S. - How can you help?
Donate cash, emergency relief information
http://dailynews.yahoo.com/fc/US/Emergency_Information/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to