Can you reverse the string and use lookahead?

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

--- Uri Guttman <[EMAIL PROTECTED]> 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
> 


=====
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Quantum Mechanics: The dreams stuff is made of


                
__________________________________
Do you Yahoo!?
Yahoo! Mail - Helps protect you from nasty viruses.
http://promotions.yahoo.com/new_mail

Reply via email to