For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > October 2004 > Extending the line input (angle) operator









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Extending the line input (angle) operator
Andrew Dunbar

2004-10-28, 8:56 am

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?
Peter Wyzl

2004-10-28, 8:56 am

"Andrew Dunbar" <hippytrail@gmail.com> wrote in message
news:ba1b6b9f.0410280049.2cbce46b@posting.google.com...
>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)

--
Wyzelli
print map{++$_;y{0-9A-Za-mn-z;}
{0-9A-Za-no-y z;}ds;$_}split '',
reverse 'qdjbzGykqdOyqdgsnmzysrtI';


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com