in reply to multiple "newline" delimiters

Bit of a restructure, but you could do something like this:

my $place = 0; my ($buffer, $line) = (undef, undef); while (sysread INPUT, $buffer, 1, $place) { $place++; if ( $buffer=~ m{;|/} ) { my_process_line($line); $line = undef; } else { $line .= $buffer; } }

There are, of course, problems with that code; but, the general concept should work. I don't know how fast it would be, but...

Yoda would agree with Perl design: there is no try{}

Replies are listed 'Best First'.
Re^2: multiple "newline" delimiters
by monarch (Priest) on Jun 01, 2005 at 00:32 UTC
    I would most often use this approach myself. It, at least, will handle any situation thrown at it.

    Unfortunately you also have to execute my_process_line($line) after the while loop to deal with the very last line/block.

    Also, you'd need to consider the impact if there were multiple matches within the buffered line.

    Finally if there were multiple matches on the buffered line you'd want to discard the processed data but retain that portion of the buffer at the end that didn't match so it could be appended to the next buffer read.

Re^2: multiple "newline" delimiters
by lgordoncurtis (Initiate) on Jun 01, 2005 at 13:46 UTC
    That worked pretty well. Because I have another procedure to deal with things like PL/SQL procedures and functions, I had to rework it a little, so here's what I came up with. Another function calls this bit of code.
    my ($buffer, $line) = (undef, undef); my $read = true; while ($read) { $buffer = $curline->getline(); if ( $buffer =~ m{;|/} ) { $read = undef; } $line .= $buffer; } process_SQL($line);
    That won't handle the case where the lines are stacked up right on top of each other, but I think it'll work for the cases where we need it to.