February 2013 Archives

Perl I/O on scalars for 5.18

From perl 5.17.9, the following:

my $scalar;
...
open my $fh, "<", \$scalar or die;

will fail unless $scalar contains only code points 0xFF or lower - ie. they can be represented as bytes.

Perl's I/O will also treat the code points contained in the scalar as bytes - character \xA1 will be read as that byte, whether perl's internal representation is as UTF-8 or as bytes (or for the internals minded, whether SVf_UTF8 is on or not.)

Unfortunately in some cases this leads to a silent change in behaviour.

About Tony Cook

user-pic I blog about Perl.