Extending the line input (angle) operator

A

Andrew Dunbar

I would like to extend the line input operator to treat something
other than CR/LF/CRLF as the end of line character.

I'm scanning very very large structured files which contain very few
end of line characters yet the structure is such that another set
string of characters has the same semantics "),(" in this case.

Naturally I could use fgetc or buffered reads or link to a C routine
but this seems like exactly the kind of thing Perl usually allows
insteading of needing to reivent.

Is there a way to extend this operator in current Perl?
If not, is there a module which offers what I want?
If not, would anybody care to recommend the quickest, most effective
way to reach my goal of a line-reading function in Perl which thinks
of a "line" as ending with "),(" rather than \n?
 
P

Peter Wyzl

Andrew Dunbar said:
I would like to extend the line input operator to treat something
other than CR/LF/CRLF as the end of line character.

I'm scanning very very large structured files which contain very few
end of line characters yet the structure is such that another set
string of characters has the same semantics "),(" in this case.

Naturally I could use fgetc or buffered reads or link to a C routine
but this seems like exactly the kind of thing Perl usually allows
insteading of needing to reivent.

Is there a way to extend this operator in current Perl?
If not, is there a module which offers what I want?
If not, would anybody care to recommend the quickest, most effective
way to reach my goal of a line-reading function in Perl which thinks
of a "line" as ending with "),(" rather than \n?

The standard variable $/ is what you are looking for.

set $/ to be what you want (before the read)...

$/ = '),(';

Even better, localise it within a block.

$/ is "\n" here...

{
local $/ = '),(';
#read with <> here...
}

$/ back to default "\n" here...

Check it out in perlvar (INPUT_RECORD_SEPARATOR)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top