in reply to Re^2: Using "binmode ???, ':encoding(UTF-8)" on the result from "qx//" ?
in thread Using "binmode ???, ':encoding(UTF-8)" on the result from "qx//" ?

On a related note , in case anyone was wondering, that doesn't affect the DATA filehandle
#!/usr/bin/perl -- use strict; use warnings; use open qw' :std IO :encoding(UTF-8) '; use autodie; Main(@ARGV); exit(0); sub Main { open my ($ThisFh), '<', __FILE__; PrintLayers( \*DATA, \*STDOUT, $ThisFh ); close $ThisFh; } sub PrintLayers { for my $Fh (@_) { print "$Fh $_\n" for PerlIO::get_layers($Fh); print "\n"; } } ## end sub PrintLayers __DATA__ GLOB(0x9b083c) unix GLOB(0x9b083c) crlf GLOB(0x979d5c) unix GLOB(0x979d5c) crlf GLOB(0x979d5c) encoding(utf-8-strict) GLOB(0x979d5c) utf8 GLOB(0x3d8b0c) unix GLOB(0x3d8b0c) crlf GLOB(0x3d8b0c) encoding(utf-8-strict) GLOB(0x3d8b0c) utf8
  • Comment on Re^3: Using "binmode ???, ':encoding(UTF-8)" on the result from "qx//" ?
  • Download Code

Replies are listed 'Best First'.
Re^4: Using "binmode ???, ':encoding(UTF-8)" on the result from "qx//" ?
by ikegami (Patriarch) on Mar 31, 2010 at 20:34 UTC
    That's not quite accurate.
    $ perl 832144.pl GLOB(0x84250b8) unix GLOB(0x84250b8) perlio GLOB(0x8248600) unix GLOB(0x8248600) perlio GLOB(0x8248600) encoding(utf-8-strict) GLOB(0x8248600) utf8 GLOB(0x82610d8) unix GLOB(0x82610d8) perlio $ perl -e'use open qw( :std IO :encoding(UTF-8) ); do $ARGV[0];' 83214 +4.pl GLOB(0x84dbdc8) unix GLOB(0x84dbdc8) perlio GLOB(0x84dbdc8) encoding(utf-8-strict) GLOB(0x84dbdc8) utf8 GLOB(0x82ff610) unix GLOB(0x82ff610) perlio GLOB(0x82ff610) encoding(utf-8-strict) GLOB(0x82ff610) utf8 GLOB(0x8570378) unix GLOB(0x8570378) perlio

    The DATA handle is actually the one the parser uses to read the source. use open won't affect the DATA of the file in which the use open occurs since it was opened before the use open was encountered.

    use utf8;, on the other hand, will affect the local DATA. You could get some "interesting" interactions.

    Your best bet is

    binmode(DATA, ':encoding(UTF-8)');