perldesire has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

How to use -0 (Zero) option in perl?

options says that 0777 to read whole file.

but I tried like perl -0777 -e 'print' filename it prints nothing.

Kindly give more details..

Replies are listed 'Best First'.
Re: How to use -0 (zero) option in perl
by ELISHEVA (Prior) on Jul 07, 2009 at 12:25 UTC

    -0 only says how to read. You also need to tell perl to read the file :-). Like this: perl -0777 -ne 'print' foo.out. (The "n" option tells perl to read.)

    Best, beth

      There's no reason to use -0777 in that example.

      perl -0777 -ne'print' in.txt

      and

      perl -ne'print' in.txt

      produce the same output. The difference is the former only loops once since it loaded the entire file into memory at once. The latter reads and prints a line at a time.

      You can see the difference in the following:

      perl -0777 -nle'print "[[[$_]]]"' in.txt

      and

      perl -nle'print "[[[$_]]]"' in.txt
        Thank you so much for your reply.
Re: How to use -0 (zero) option in perl
by Anonymous Monk on Jul 07, 2009 at 12:16 UTC
    Start with perlintro
    $ perl -MO=Deparse,-p -0777 -e 'print' BEGIN { $/ = undef; $\ = undef; } '???'; -e syntax OK $ perl -MO=Deparse,-p -0777 -pe 'print' BEGIN { $/ = undef; $\ = undef; } LINE: while (defined(($_ = <ARGV>))) { '???'; } continue { print($_); } -e syntax OK $ perl -MO=Deparse,-p -0777 -ne 'print' BEGIN { $/ = undef; $\ = undef; } LINE: while (defined(($_ = <ARGV>))) { '???'; } -e syntax OK
      You goofed your quotes on windows :)
      $ perl -MO=Deparse,-p -0777 -e print BEGIN { $/ = undef; $\ = undef; } print($_); -e syntax OK $ perl -MO=Deparse,-p -0777 -pe print BEGIN { $/ = undef; $\ = undef; } LINE: while (defined(($_ = <ARGV>))) { print($_); } continue { (print($_) or die("-p destination: $!\n")); } -e syntax OK $ perl -MO=Deparse,-p -0777 -ne print BEGIN { $/ = undef; $\ = undef; } LINE: while (defined(($_ = <ARGV>))) { print($_); } -e syntax OK