develooper Front page | perl.perl5.porters | Postings from February 2009

[perl #63124] Inconsistent warning for hex escape

From:
Bram via RT
Date:
February 15, 2009 11:05
Subject:
[perl #63124] Inconsistent warning for hex escape
Message ID:
rt-3.6.HEAD-12283-1234607383-59.63124-15-0@perl.org
> $ perl -wle'"a\x1"=~s/a(?=\x1)//'
> Illegal hexadecimal digit ')' ignored at -e line 1.
> Illegal hexadecimal digit ')' ignored at -e line 1.
> Can't modify constant item in substitution (s///) at -e line 1, at EOF
> Execution of -e aborted due to compilation errors.
> 
> The documented syntax for hex escapes is \xHH
> 
> * Why do I get a double warning
> * Why does the assignment not warn
> 
> $ perl -wle'$_="a\x1)"'
> Illegal hexadecimal digit ')' ignored at -e line 1.
> 
> Here it *does* warn
> 
> Same behaviour in 5.8.8
> 

(also said on #p5p)

$_="a\x1"; does not warn since there are no characters after the 1.
m/a\x1/;  also does not warn


If we look at octal:

$ perl -wle 'print "\01A";'
A


$ perl -wle 'print "\018";'
Illegal octal digit '8' ignored at -e line 1.
8


Doing a similar thing for hex should be possible (only warn if the 
symbol is in the [G-Zg-z] range) but I personally see very little value 
in this warning.

A warning about \018 is useful since the user might be confusing 
decimal with octal... But with what can you possible confuse \x1Z ?



Kind regards,

Bram




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About