in reply to Why doesn't this work?

try $/="\0"

unquoted \0 is a reference to a literal number (i.e. read-only scalar) ...

DB<135> $/=\0 => \0 DB<136> ref $/ => "SCALAR" DB<137> ${$/} => 0

... and not the escape sequence for NUL byte!

DB<146> $/="\0" => "\0" DB<147> ord $/ => 0

Cheers Rolf

( addicted to the Perl Programming Language)

Replies are listed 'Best First'.
Re^2: Why doesn't this work?
by perl-diddler (Chaplain) on Apr 12, 2013 at 21:57 UTC
    *Bingo*. That was it! *doh!* <palmslaps self>
      maybe shorter?

      DB<178> open $fh,"<",\"1\0 2\0 3" DB<179> print scalar do {local $/="\0"; () = <$fh> } 3

      update
      as one liner
      perl -e '$/="\0"; print $a=()=<>'

      Cheers Rolf

      ( addicted to the Perl Programming Language)

        Even shorter:
        {local $/="\0"; () = <$fh>; print $.}
        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ