in reply to Re^12: How do I display only matches (updated)
in thread (SOLVED) How do I display only matches

The default on *nix is equivalent to using :raw, which also creates a portability issue since binmode is unnecessary for handling binary data on POSIX — it "just works" until someone runs the program on Windows and bytes start disappearing. :-)

Replies are listed 'Best First'.
Re^14: How do I display only matches (updated)
by Anonymous Monk on Sep 30, 2019 at 03:50 UTC
    The default on *nix is equivalent to using :raw, which also creates a portability issue since binmode is unnecessary for handling binary data on POSIX — it "just works" until

    Thanks for explaining this puzzling behavior, as seen by fiddling with haukex's oneliner (on darwin):

    
    perl -wMstrict -MData::Dump -e "dd PerlIO::get_layers(STDOUT)"
    ("unix", "perlio")
    
    perl -wMstrict -MData::Dump -e "STDOUT->binmode(':raw');dd PerlIO::get_layers(STDOUT)"
    ("unix", "perlio")
    
    perl -wMstrict -MData::Dump -e "STDOUT->binmode(':utf8');dd PerlIO::get_layers(STDOUT)"
    ("unix", "perlio", "utf8")
    
    perl -wMstrict -MData::Dump -e "STDOUT->binmode(':encoding(UTF-8)');dd PerlIO::get_layers(STDOUT)"
    ("unix", "perlio", "encoding(utf-8-strict)", "utf8")
    
Re^14: How do I display only matches (updated)
by Anonymous Monk on Sep 29, 2019 at 04:04 UTC

    And what happens when you're reading from a mounted partition?

    Those who want raw data use binmode or :raw

    All others gamble

      Technically, even / is a mount point — or are you talking about the (raw) devices?

      You are wrong. The binmode FILEHANDLE operator in Perl is a no-op on POSIX, just as the binary mode option to fopen(3) is a no-op on POSIX. I said this was a portability problem, and it is a portability problem, but programs that never use binmode will handle binary data just fine on POSIX. They will fail on other systems where text and binary streams are actually different.

        The binmode FILEHANDLE operator in Perl is a no-op on POSIX

        Sorry, no - it still removes any non-default layers that may be present on the filehandle. Even a handle opened with the default open my $fh, '<', ... can have layers other than the normal defaults present due to the PERLIO environment variable or the open pragma.