How about this?

    return grep(/./s, $$bufref =~ m#(.*?)(?:$sep|\z)#gs) if wantarray;

Josh

On Sep 16, 2004, at 11:05 PM, Uri Guttman wrote:


in file::slurp i currently split the file into lines (or records based on $/) using this code:

        return split( m|(?<=$sep)|, ${$buf_ref} ) if wantarray ;

where $sep is set from $/.

that works correctly and is fast. but it has one flaw, it can't do
paragraph mode since lookbehind can't handle variable width regexes as
\n\n+ is. so i am looking for an m// solution that properly splits a
buffer into records. it is not as easy as it seems. it has to behave
exactly like the split does. there are several corner cases such as an
empty file and a partial line ending a file. even a normal file of lines
is tricky as you don't want to return an bogus empty line after the last
real line. here are a few broken attempts to help you avoid pitfalls:


        /(.*?$sep|.+)/sg        # doesn't handle an empty file
        /.*?(?:$sep|\z)/gs      # adds a bogus empty line at the end

i already passed this problem to a top regex person and he sent me the
second one above (obviously untested! :).

so fame, glory and an acknowledgement in the new release all go to the
valiant warrior who solves this.

let the fl^Wgames begin!

uri

--
Uri Guttman ------ [EMAIL PROTECTED] -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org



Reply via email to