What's the effect of a null input record separator?

Discussion in 'Perl Misc' started by here@softcom.net, Oct 19, 2013.

  1. Guest

    Given the one-liner:

    perl -0ne 'print "$ARGV\n" if [some condition];' *

    What effect does the -0 have on each file? I know the values for paragraph mode 00 and file slurp mode 0777, but I can't find a definitive answer on when $/ is set to the null character.
     
    , Oct 19, 2013
    #1
    1. Advertising

  2. * wrote in comp.lang.perl.misc:
    >Given the one-liner:
    >
    >perl -0ne 'print "$ARGV\n" if [some condition];' *
    >
    >What effect does the -0 have on each file? I know the values for
    >paragraph mode 00 and file slurp mode 0777, but I can't find a
    >definitive answer on when $/ is set to the null character.


    http://search.cpan.org/perldoc?perlvar "Trying to set the record size
    to zero or less will cause reading in the (rest of the) whole file."
    --
    Björn Höhrmann · mailto: · http://bjoern.hoehrmann.de
    Am Badedeich 7 · Telefon: +49(0)160/4415681 · http://www.bjoernsworld.de
    25899 Dagebüll · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
     
    Bjoern Hoehrmann, Oct 19, 2013
    #2
    1. Advertising

  3. Guest

    On Saturday, October 19, 2013 8:38:35 AM UTC-7, wrote:
    > Given the one-liner:
    >
    >
    >
    > perl -0ne 'print "$ARGV\n" if [some condition];' *
    >
    >
    >
    > What effect does the -0 have on each file? I know the values for paragraph mode 00 and file slurp mode 0777, but I can't find a definitive answer on when $/ is set to the null character.
     
    , Oct 19, 2013
    #3
  4. Guest

    On Saturday, October 19, 2013 8:38:35 AM UTC-7, wrote:
    > Given the one-liner:
    >
    >
    >
    > perl -0ne 'print "$ARGV\n" if [some condition];' *
    >
    >
    >
    > What effect does the -0 have on each file? I know the values for paragraph mode 00 and file slurp mode 0777, but I can't find a definitive answer on when $/ is set to the null character.


    ########################

    So does that mean that -0 on the command line is equivalent to:

    undef $/;
    while (<>) {
    ...
    }
     
    , Oct 19, 2013
    #4
  5. wrote:
    > Given the one-liner:
    >
    > perl -0ne 'print "$ARGV\n" if [some condition];' *
    >
    > What effect does the -0 have on each file? I know the values for
    > paragraph mode 00 and file slurp mode 0777, but I can't find a
    > definitive answer on when $/ is set to the null character.


    $ perl -MO=Deparse -0ne 'print "$ARGV\n" if [some condition];' *
    BEGIN { $/ = "\000"; $\ = undef; }
    LINE: while (defined($_ = <ARGV>)) {
    print "$ARGV\n" if ['condition'->some];
    }
    -e syntax OK

    The value "\0" will be used as the record separator so if you have a
    "text" file it is the same as slurp mode but if you have a "binary" file
    you will get as many records as there are "\0" characters in the file.


    John
    --
    Any intelligent fool can make things bigger and
    more complex... It takes a touch of genius -
    and a lot of courage to move in the opposite
    direction. -- Albert Einstein
     
    John W. Krahn, Oct 19, 2013
    #5
  6. Tim McDaniel Guest

    In article <>,
    Ben Morrow <> wrote:
    >
    >Quoth :
    >> * wrote in comp.lang.perl.misc:
    >> >Given the one-liner:
    >> >
    >> >perl -0ne 'print "$ARGV\n" if [some condition];' *
    >> >
    >> >What effect does the -0 have on each file? I know the values for
    >> >paragraph mode 00 and file slurp mode 0777, but I can't find a
    >> >definitive answer on when $/ is set to the null character.

    >>
    >> http://search.cpan.org/perldoc?perlvar "Trying to set the record
    >> size to zero or less will cause reading in the (rest of the) whole
    >> file."

    >
    >Not relevant. That's talking about $/ = \0,


    Do you mean
    $/ = 0
    or is there something special about a scalar reference to 0?

    --
    Tim McDaniel,
     
    Tim McDaniel, Oct 20, 2013
    #6
    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. bjam
    Replies:
    3
    Views:
    4,067
  2. Angelic Devil

    Record separator for readlines()

    Angelic Devil, Sep 2, 2005, in forum: Python
    Replies:
    3
    Views:
    309
    Bengt Richter
    Sep 3, 2005
  3. Lee Sander
    Replies:
    6
    Views:
    300
    Hendrik van Rooyen
    Jun 1, 2007
  4. Steve Howell
    Replies:
    3
    Views:
    288
    George Sakkis
    Jun 2, 2007
  5. Johny

    Readline and record separator

    Johny, Oct 30, 2007, in forum: Python
    Replies:
    12
    Views:
    731
    Dennis Lee Bieber
    Nov 2, 2007
Loading...

Share This Page