On Mon, 20 Nov 1995, Ed Peschko wrote:
> hey --
>
> I was wondering (another bug/feature thing) if ?= was supposed to leave
> backreferences... ie:
>
> $text =~ /(text (?=lookahead_text))/;
>
> ie -- should:
>
> print $1;
>
> print out:
>
> text
>
> or print out:
>
> text lookahead text
>
>
> The first seems to be the case -- however in perlref I see no mention of the
> fact that (?=pattern) does not make backreferences..
Wrong and right. (?=...) is negative width, but does leave
backreferences. See this:
~$ perl -e '$_ = "abc"; m/(a(?=b(c)))/; print "$1, $2, $3, $4\n"'
a, c, ,
You see, by the time it gets to the outermost closing paren (to finish
$1) the position has been reset to just after "a". But within the (?=...)
the parens get closed normally, and thus $2 arises.
> Ed
>
> PS: I am using this in an iterative context to find perl expressions, ie:
>
>
> while ($text =~ /\b(([a-z]+)(?=\s.*.*?\;))/sg) {
> $statement = $1;
> $bareword = $2;
> if ($perl_word{$bareword} == $TRUE) {
> push(@perl_expressions, $statement);
> $text =~ /\;/sg;
> }
> }
>
> This *should* give a list of all the perl expressions in a program with high
> probability (and assuming no syntax errors in the statement).
>
> Ed
>
--
Kenneth Albanowski (kjahds@kjahds.com, CIS: 70705,126)