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
> "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 :)
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)|
How about
/.*?$sep|.+|^\z/sg
Seems to work alright for empty file as well as incomplete lines,
without producing bogus empty lines.
- Karsten
> "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
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
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 han