Well, anyway, I did a little work on it and found myself amused by the following code, which I thought you might enjoy:
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.# 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; }
Exercise: Would this be improved with a judicious application of /x?
--
Mark Dominus
Perl Paraphernalia
|
|---|