in reply to Using a regex to catch interpreters
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.#!/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/; }
One world, one people
|
|---|