Extending the line input (angle) operator

Discussion in 'Perl Misc' started by Andrew Dunbar, Oct 28, 2004.

  1. 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?
     
    Andrew Dunbar, Oct 28, 2004
    #1
    1. Advertising

  2. Andrew Dunbar

    Peter Wyzl Guest

    "Andrew Dunbar" <> wrote in message
    news:...
    >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';
     
    Peter Wyzl, Oct 28, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?U3VyYWpQcmFiaHU=?=

    Drawing line at an angle in ASP.nt

    =?Utf-8?B?U3VyYWpQcmFiaHU=?=, Jun 8, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    419
    =?Utf-8?B?U3VyYWpQcmFiaHU=?=
    Jun 8, 2006
  2. Dietrich Bollmann
    Replies:
    0
    Views:
    375
    Dietrich Bollmann
    Apr 22, 2008
  3. Keith Hughitt

    Angle brackets in command-line arguments?

    Keith Hughitt, Jul 16, 2008, in forum: Python
    Replies:
    4
    Views:
    655
    Keith Hughitt
    Jul 16, 2008
  4. John Bullock
    Replies:
    5
    Views:
    136
    Anno Siegel
    Aug 30, 2004
  5. Ed Mancebo

    angle operator, backticks, and redirection

    Ed Mancebo, Jan 12, 2005, in forum: Perl Misc
    Replies:
    6
    Views:
    149
    Tad McClellan
    Jan 13, 2005
Loading...

Share This Page