develooper Front page | perl.perl5.porters | Postings from October 2013

[perl #119499] $! returned with UTF-8 flag under UTF-8 locales only under 5.19.2+

Thread Previous
Victor Efimov via RT
October 16, 2013 11:28
[perl #119499] $! returned with UTF-8 flag under UTF-8 locales only under 5.19.2+
Message ID:
On Tue Oct 15 14:59:45 2013, wrote:
> What you want is for $! to work like it's in 'use bytes'.  I can change 
> the patch so that it checks for 'use bytes' and if within that scope 
> returns without the utf8 flag set.  You would then just need to add a 
> 'use bytes' to get it to work the same way it always has.
> There are people who would disapprove of ever using bytes, which means 
> they think the behavior you want is wrong.  I'm not one of them.  I 
> think that 'use bytes' should be rare, mostly used in testing, but it 
> sometimes is the easiest, clearest way of getting at the bytes that 
> comprise a UTF-8-encoded character.  utf8::encode() can be used for 
> that, but destroys its argument and I think its name is much less clear 
> than 'use bytes'.
> I have tested doing this, and it works.

New behaviour looks sane to me. It's probably thay way it's supposed to
work from beginning. Main problem solved (when $! sometimes returned
characters, sometimes bytes).

There were comments that enabling new behaviour in lexical scope is not
good and danger (but you stated that it's probably OK). We enabled it by
default, and users now can switch to *old* behaviour in *lexical* scope
(with use bytes or use locale). I think arguments that lexical scope is
not good can apply here too.

The big problem that I see now is backward compatibility. Any existing
code that uses $! is probably broken.

Users will have to fix it with use locale/use bytes.

Few examples that I found (where filenames are concatenated with $!):

        unless ($!{EEXIST}) {
          ${$options{ErrStr}} = "Could not create temp file $path: $!";
          return ();

	    unless (defined $topnlink) {
		warnings::warnif "Can't stat $top_item: $!\n";
		next Proc_Top_Item;

	my @stat        = stat($tmpfile) or die "Could not stat tmpfile
'$tmpfile': $!";
	or die "Cannot rename '$tmpfile' to '$file': $!\n";


Note, that if filename here contains non-ASCII characters and is binary
string, merging it with character string $! would produce broken result.

Even if filename is ASCII, it would break old behaviour when die
exception printed to STDERR.

If filename is character string, that code did not work correctly

Another issue that there is POSIX::strerror, and IMHO it should behave
just like $! for consistency (i.e. produce different things depending on
lexical scope). POSIX::strerror is pure perl.

via perlbug:  queue: perl5 status: open

Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About