- publishing free software manuals
Perl Language Reference Manual
by Larry Wall and others
Paperback (6"x9"), 724 pages
ISBN 9781906966027
RRP £29.95 ($39.95)

Sales of this book support The Perl Foundation! Get a printed copy>>>


Octal escapes potentially clash with backreferences. They both consist of a backslash followed by numbers. So Perl has to use heuristics to determine whether it is a backreference or an octal escape. Perl uses the following rules:

  1. If the backslash is followed by a single digit, it's a backreference.
  2. If the first digit following the backslash is a 0, it's an octal escape.
  3. If the number following the backslash is N (decimal), and Perl already has seen N capture groups, Perl will consider this to be a backreference. Otherwise, it will consider it to be an octal escape. Note that if N > 999, Perl only takes the first three digits for the octal escape; the rest is matched as is.
    my $pat  = "(" x 999;
       $pat .= "a";
       $pat .= ")" x 999;
    /^($pat)\1000$/;   #  Matches 'aa'; there are 1000 capture groups.
    /^$pat\1000$/;     #  Matches 'a@0'; there are 999 capture groups
                       #    and \1000 is seen as \100 (a '@') and a '0'.
ISBN 9781906966027Perl Language Reference ManualSee the print edition