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