Re: What should /\08/ match and do?

[email protected] (Abigail)
Newsgroups perl.perl5.porters
Message-ID <20100601203000.GB12847@almanda>
On Tue, Jun 01, 2010 at 11:52:38AM -0600, karl williamson wrote:
>
> What about \008 ?  The pods say that a two or three digit octal number  
                                                      ^^^^^^^^^^^  Hmmm ;-)
> follows a backslash, but it turns out that a single digit "works" in  
> character classes, eg. [\7]

The reason backslash followed by a 'single' octals (except for \0)
isn't a character escape is that they are backreferences; regardless
of the number of capturing parenthesis. A backslash followed by two or
three octals is only a character espace if it either starts with a 0,
or cannot be a backreference (due to lack of capturing parenthesis).
(Interestingly enough, the numbers are interpreted as digits when it's
a backreference; and as octals when being a numeric escape).  But inside
a bracketed character class, you cannot have a backreference - so \7 is
an octal escape.

IMO, this potential confusion of \OOO being either an octal escape, or a
backreference is a more serious problem than \008. For instance,

    /(.)(.)(.)(.)(.)(.)(.)(.)(.)\10/

will suddenly match something else if another set of parens is introduced:

    /((.)(.)(.)(.)(.)(.)(.)(.)(.))\10/

This one is sneaky as well:

    $a = '(.)\1';
    "aa" =~ /${a}/;      # True
    "aa0" =~ /${a}0/;    # False!
    "aa\x8" =~ /${a}0/;  # True!

I try to always use \g{} when using backreferences, and avoid octal character
escapes, but it's hard to kill a habit. (And $WORK still uses 5.8.5...)

If I had a time machine, I'd go back in time, and, using the power of
hindsight, explained to Larry it would be better to mandate a leading
0 for octal escapes. Or better yet, to use \g{} for backrefences from
the start.

> What about \x{} ?  It currently yields \000 silently.  I originally
> proposed deprecating it, but this met objections, but I do think it  
> should warn, even if not deprecated.

I'm not easily convinced about introducing warnings about constructs that
have been around of a long time. Do you have any evidence there are many
people using "\x{}", and expecting it to match something other than \000?
If not, I don't see any benefit for a warning; it won't help people, and
it will annoy people who have been using "\x{}" to match "\000".

> \N{} yields two errors, one correct, one misleading:
> ./perl -Mcharnames=:full -Ilib -E '"\N{}"'
> Unknown charname '' at lib/unicore/Name.pl line 1
> Deprecated character in \N{...}; marked by <-- HERE  in \N{}<-- HERE  at  
> -e line 1.
>
> And there is:
>  ./perl -Mcharnames=:full -Ilib -E '"\N{U+}"'
> Invalid hexadecimal number in \N{U+...} at -e line 1, within string
> Execution of -e aborted due to compilation errors.


I don't have a problem with them being errors. I don't have a problem
with them being funky ways of writing "\000" either (but then, it should
be documented, and not warn).



Abigail
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.