On Friday, April 19, 2002, at 03:09 , Jeff 'japhy' Pinyan wrote:
[..]
> First, I'd use a regex trick of //g in scalar context, and /^/m.
>
>   while (<FH>) {
>     next unless /^$prefix/;
>     $_ .= <FH> while /^$prefix/gm;
>     print;
>   }

I'm not sure I understand the 'exit' strategy here.
assume the file is:

        bob
        >line1
        fred
        line2
        line3
        >line4
        alice

we toss bob.
we have $_ == >line1\n
        then $_ == >line1\nfred\n
        then $_ == >line1\nfred\nline2\n

because the line is still starting with the prefix....

since we have no exit from the while, even after we
have read the whole of the file, we go back and keep
appending onto the $_ the EOF mark......

and never advance to the print statement...

but on the flip side, while that has a logic fault
the conclusion:

>       /^$prefix/ .. !/^$prefix/ and print while <FH>;

actually works as advertised....


ciao
drieux

---


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

Reply via email to