- 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>>>

12.6.2 Relative referencing

New in perl 5.10.0 is a different way of referring to capture buffers: \g. \g takes a number as argument, with the number in curly braces (the braces are optional). If the number (N) does not have a sign, it's a reference to the Nth capture group (so \g{2} is equivalent to \2 - except that \g always refers to a capture group and will never be seen as an octal escape). If the number is negative, the reference is relative, referring to the Nth group before the \g{-N}.

The big advantage of \g{-N} is that it makes it much easier to write patterns with references that can be interpolated in larger patterns, even if the larger pattern also contains capture groups.

Mnemonic: group.

ISBN 9781906966027Perl Language Reference ManualSee the print edition