Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: qr//x and \# weirdness (AS 5.8?)

by Chmrr (Vicar)
on May 28, 2003 at 05:28 UTC ( #261227=note: print w/replies, xml ) Need Help??

in reply to qr//x and \# weirdness (AS 5.8?)

The problem is around line 3000 in sv.c; the comment there reads:

/* * If /x was used, we have to worry about a regex * ending with a comment later being embedded * within another regex. If so, we don't want this * regex's "commentization" to leak out to the * right part of the enclosing regex, we must cap * it with a newline. * * So, if /x was used, we scan backwards from the * end of the regex. If we find a '#' before we * find a newline, we need to add a newline * ourself. If we find a '\n' first (or if we * don't find '#' or '\n'), we don't need to add * anything. -jfriedl */

This is only a display bug -- it doesn't effect the way the regex matches.

It looks like it's not looking earlier than the # to see if the # is preceeded by a \. Unfortunately, I don't think it's just that easy, either, as qr[ \\# ] should get the newline..

perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&V"+@( NO CARRIER'

Replies are listed 'Best First'.
Re: Re: qr//x and \# weirdness (AS 5.8?)
by BrowserUk (Pope) on May 28, 2003 at 06:06 UTC

    I don't have bleedperl, but something like this (simulated!) diff might work? (I scrunched it a bit).

    @ 2992 sv.c (5.8.0) if (PMf_EXTENDED & re->reganch) { char *endptr = re->precomp + re->prelen; while (endptr >= re->precomp) { char c = *(endptr--); if (c == '\n') break; /* don't need another */ if (c == '#') { + int n =0; + while( endptr >= re->precomp && + c = *(endptr--) && + c == '\' ) n++; + /* if we've an odd number of backslashes the # + is escaped, so don't need the newline */ + + if ( n & 1) break; /* we end while in a comment, so we need a newline */ mg->mg_len++; /* save space for it */ need_newline = 1; /* note to add it */ } } }

    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://261227]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2021-04-14 07:35 GMT
Find Nodes?
    Voting Booth?

    No recent polls found