in reply to About $/

No, because, as perlvar says, “the value of $/ is a string, not a regex.” — and a string can hold only one value at a time.

Perhaps you can proceed in this way: Pick one of the two end-line strings (say, \r) and assign it to $/. Then, split each line on the other end-line character (\003) and process each string as a “line.”

Or, if your file isn’t too big, you can slurp it all into memory and then split using a regex:

19:55 >perl -MData::Dump -wE "my $s = qq[fred\rwilma\003barney\rbetty\ +003]; my @lines = split /\r|\003/, $s; dd @lines;" ("fred", "wilma", "barney", "betty") 19:56 >

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: About $/
by FloydATC (Deacon) on May 24, 2013 at 10:52 UTC
    If all else fails, use sysread() to implement your own read buffering and split the incoming data on the fly.

    open(my $fh, '/my/huge/file') || die $!; binmode $fh; my $separator = "\r*\n|\t|whatever"; my $buffer = ''; my $block; while (sysread($fh, $block, 4096)) { $buffer .= $block; while ($buffer =~ /$separator/) { process_line($`.$&); # prematch + match $buffer = $'; # postmatch } } print "--\n"; process_line($buffer) if $buffer; # remainder, if any. close $fh;

    This gives you full control over how to split the data into lines, without significant memory overhead.

    -- Time flies when you don't know what you're doing