Re: tough regex problem

2004-09-18 Thread Ramki
suboptimal, but works correctly for all input files below. #--- return unless wantarray; return unless $$buf_ref =~ /./; return (${$buf_ref} =~ /.*?(?:$sep{2}|\z)/gs) if $paragraph_mode; return (${$buf_ref} =~ /.*?(?:$sep|\z)/gs ); #--- test

tough regex problem

2004-09-17 Thread Uri Guttman
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

Re: tough regex problem

2004-09-17 Thread Josh Goldberg
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

Re: tough regex problem

2004-09-17 Thread Uri Guttman
JG == Josh Goldberg [EMAIL PROTECTED] writes: JG How about this? JG return grep(/./s, $$bufref =~ m#(.*?)(?:$sep|\z)#gs) if wantarray; check that on an empty file. it needs to return a null string for that. the grep will fail there. and i don't want to filter it through grep as that

Re: tough regex problem

2004-09-17 Thread Karsten Sperling
How about /.*?$sep|.+|^\z/sg Seems to work alright for empty file as well as incomplete lines, without producing bogus empty lines. - Karsten

Re: tough regex problem

2004-09-17 Thread Uri Guttman
QM == Quantum Mechanic [EMAIL PROTECTED] writes: QM Can you reverse the string and use lookahead? QM return split( m|(?=$sep)|, reverse ${$buf_ref} ) if QM wantarray ; this is file slurping. would you want the lines in reverse order? if so you would use File::ReadBackwards :) you could