Someone in comp.lang.perl.misc wants to turn man pages into HTML. Apparently he doesn't know that you should do this before you run nroff to convert them to plain text; he's trying to convert the output of the man command. Oops!

Well, anyway, I did a little work on it and found myself amused by the following code, which I thought you might enjoy:

# obfuscated? You should have seen it before I cleaned it up while (<>) { my $changed; while (/(.*?)((?:(.)\cH\3)+)/s) { my $tobold = $2; my $start = length $1; $tobold =~ s/(.)../$1/g; substr($_, $start, 3 * length $tobold) = "<b>$tobold</b>"; } while (/(.*?)((?:_\cH.)+)/s) { my $toital = $2; my $start = length $1; $toital =~ s/..(.)/$1/g; substr($_, $start, 3 * length $toital) = "<i>$toital</i>"; } print; }
To try this out, use man cat | undo_nroff.pl. It doesn't handle the pre sections, but that's OK because the whole exercise was a waste of time anyway. But the code might be instructive. The useful use of .*? is unusual.

Exercise: Would this be improved with a judicious application of /x?

--
Mark Dominus
Perl Paraphernalia