multiline

H

hawk.alan

open(FILE,$ARGV[0]);

while(<FILE>){
if (/falls mainly on.*l /s){ print"1";};
print;
}


the rain in spain
falls mainly on the
plain

isn't matching across the line. plz help. The /s modifier doesn't seem
to be
working.
 
H

hawk.alan

:( .

At least I know now.

It does mean I'm gonna have to change the rest of my script to
accommadate for slurping(ie. $/="").
 
D

Dr.Ruud

(e-mail address removed) schreef:
open(FILE,$ARGV[0]);

while(<FILE>){
if (/falls mainly on.*l /s){ print"1";};
print;
}


the rain in spain
falls mainly on the
plain

isn't matching across the line. plz help. The /s modifier doesn't seem
to be working.

#!/usr/bin/perl -T
use strict ;
use warnings ;

my $fn = $ARGV[0] ;
open my $fh, '<', $fn or die "<$fn> $!" ;

{ # paragraph-mode
local $/ = '' ;

while (<$fh>)
{
/falls mainly on.*l/s and print "found one\n" ;
}
}

close $fh or die "<$fn> $!" ;
 
B

Bart Lateur

It does mean I'm gonna have to change the rest of my script to
accommadate for slurping(ie. $/="").

Or you could try to use the "range" (aka "flipflop") operator, either 2
or 3 dots. Like this:

while(<FILE>){
if (my $cnt = (/falls mainly on/ ... /l/)){ print "$cnt ";};
print;
}

It'll match the first part of the pattern and continue until it either
matches the second pattern, or until it reaches the end of the file. So
after the start it'll never fail. You may want to postpone any action
until you're sure the second pattern will match, and meanwhile, buffer
the lines somewhere.

Also be aware that the flipflop won't be switched off at the end of the
file, which means it'll still be on when you read a new file. If that
matters, a reasonable behaviour could be worked out using eof.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,201
Messages
2,571,049
Members
47,655
Latest member
eizareri

Latest Threads

Top