in reply to Re: Using a regex to catch interpreters
in thread Using a regex to catch interpreters

Clarification:
>>> etc >>> etc >>> etc should be converted to PYTHON_PROMPT etc PYTHON_PROMPT etc PYTHON_PROMPT etc while >>> etc >>> etc >> etc should not. So, those read aheads / arrays / etc won't work, will they?

Also, re not using $1 for performance - it's not so much that I mind for this regex, it's that I'm under the impression that once you use $1 once, perl needs to track it for every regex in the entire program... which I don't want to slow down. Is there a way to tell Perl to only turn on $1 here, but no where else...

Replies are listed 'Best First'.
Re^3: Using a regex to catch interpreters
by ikegami (Patriarch) on Jul 06, 2005 at 18:05 UTC
    it's that I'm under the impression that once you use $1 once, perl needs to track it for every regex in the entire program...

    You're thinking of $&, $` and $'. They are always set by all regexps when they are used anywhere in the program.

    $1 .. $9 are always set by every regexps that succeeds. When a given regexp has no corresponding capture, they are set to undefined. No attention is payed to whether $1 .. $9 are used anywhere.

Re^3: Using a regex to catch interpreters
by eastcoastcoder (Sexton) on Jul 06, 2005 at 17:34 UTC
    Speaking of test, here's some code I wrote to do basic testing
    use Test::Simple tests => 7; sub cpi { # the converter goes here } $a = '>> no snake here >>> or here I agree'; $b = '>> and neither should this >>> be understood snakily >>> because it is a nested quote >> yes I know it is not really named after a snake '; $c = '>> >>>no snake >>>no snake '; $d= '>>> still no snake seen >> right! '; $snakea = '>>> i = j '; $snakeb = '>>> i = j + 1 >>> q is good code'; $snakec = '>> does this work right? lets see: >>> i = test(func) '; ok (cpi($a) eq $a); ok (cpi($b) eq $b); ok (cpi($c) eq $c); ok (cpi($d) eq $d); ok (cpi($snakea) eq 'PYTHON_PROMPT_PROTECTED i = j '); ok (cpi($snakeb) eq 'PYTHON_PROMPT_PROTECTED i = j + 1 PYTHON_PROMPT_PROTECTED q is good code'); ok(cpi($snakec) eq '>> does this work right? lets see: PYTHON_PROMPT_PROTECTED i = test(func) ');