a perl question

Maarten Litmaath maart at cs.vu.nl
Tue Nov 14 07:56:08 AEST 1989


At first I wrote it in sed:
----------8<----------8<----------8<----------8<----------8<----------
: top
	s/\(\n.*\)\n\(.\)^H\2/\1\2\
/
	t top
	s/\(.\)^H\1/\
\1\
/
	t top
	s/\n\([^\n]*\)\n/${bold}\1${endbold}/g
----------8<----------8<----------8<----------8<----------8<----------

Then I ran s2p on the script -> wrong perl script!  ('\n' is handled
incorrectly.)  A rewrite in perl:

----------8<----------8<----------8<----------8<----------8<----------
#!/usr/local/bin/perl
eval "exec /usr/local/bin/perl -S $0 $*"
	if $running_under_some_shell;

$SO = "\033[7m";
$SE = "\033[m";

line: while (<>) {
	while (1) {
		while (s/(\n.*)\n(.)\010\2/$1$2\n/) {
			;
		}
		last if !s/(.)\010\1/\n$1\n/;
	}
	s/\n(.*)\n/$SO$1$SE/g;
	print;
}
-- 
"Richard Sexton is actually an AI program (or Construct, if you will) running
on some AT&T (R) 3B" (Richard Brosseau) | maart at cs.vu.nl, mcsun!botter!maart



More information about the Comp.unix.questions mailing list