From: "JupiterHost.Net" <[EMAIL PROTECTED]>
> Mandar Rahurkar wrote:
> >    I have a bunch of text (multiple paragraphs). I want to find a
> >    sentence 
> > like 'Susan * the water' (No its not a HW problem). Here's what I am
> > doing:
> > 
> > #! /usr/bin/perl
> 
> use strict;
> 
> > use warnings;
> > 
> > $file="temp.txt";
> 
> my $file = 'temp.txt';
> 
> > open(fp,$file) or die "Cant open $file :$!\n";
> 
> open(FP,$file) or die "Can not open $file : $!\n";
> 
> > local $/="";
> 
> why ??

Because otherwise the <FP> would read individual lines. And the 
sentence can easily be split to several lines.
If you set $/ to "" then the file is read in paragraphs, not lines. 
That is each <FP> now returns several lines until it finds an empty 
one.
 
> > while (<fp>) {
> 
> while(<FP>) {
> 
> >    while( /(susan)(\D+)[the|water]\b/xig )

\D means "non-digit", What's wrong with sentence 
        Susan filled 3 glasses with the water?
And the \D+ matches as much text as it can, it won't stop on the 
first "the water".

[the|water] means exactly the same as for example [aehrtw|]. Not what 
you meant right? I believe you want something like this:

        while (/(susan[^.?!]+the\s+water\b)/ig) {
                print $1,"\n";
        }

Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to