in reply to Using a regex to catch interpreters

How about reading ahead, so simplifying the required substitution (i.e. modify the previous line of input), e.g.:

#!/usr/bin/perl use strict; my ( $prev, $this ) = ( undef(), undef() ); while( <> ) { $this = $_; /^>>[^>]/ or mySubst( \$prev ); print $prev; $prev = $this; } # finally, process the last line of input which got left over mySubst( \$prev ); print $prev; sub mySubst { my $sref = shift; $$sref =~ s/^>>>/PYTHON_PROMPT/; }
Update: Having just seen the previous post: The point of reading ahead is to avoid reading the whole file into an array - also (ahem!) the read-ahead version here is one I took a few minutes to test with suitable input.

One world, one people