Updated: It does the same thing, but it turns them into paragraphs now: see replies below. (original code is still in this post, but the URL points to the new code)
One caveat is that you shouldn't have the string that it's searching for (the result of "code" . ">", but "code" . ">" is fine) in your source code, or it'll screw up.#!/usr/bin/perl # Perl Monks Forum Post Formatter, by David Caughell, grasp_the_sun@ya +hoo.co.uk # Changes end-of-line chars to <br>'s, and avoids "code" . ">" section +s use strict; use warnings; use CGI qw(:standard -debug); # output in text format to allow cutting and pasting print "Content-type: text/plain\n\n\n"; my $post = param('FPost'); my $match = "code" . ">"; my $target = 0; my $numoccur = 0; # while there are matches from the target onwards while (index(lc($post),$match,$target) != -1) { ++$numoccur; # if they're an opening match if ($numoccur % 2 == 1) { # make substitutions from previous target to new target substr($post,$target,index(lc($post),$match,$target) - $target) =~ s/ +\n/<br>/g; } $target = index(lc($post),$match,$target) + length($match) - 1; # +the "<" } # either close the code block or do the final substitution if ($numoccur % 2 == 1) { $post = $post . $match; } else { substr($post,$target) =~ s/\n/<br>/g; } print "$post\n\n\n\n\n"; # for all you other-language programmers out there, here are some stat +istics: # lines of source: 39 # empty lines: 9 # commenting (shebang to be considered code): 7 # lines containing only "}": 4 # lines of code: 19
Update: P.P.S. Though I'd like to take that remark back, but since it was replied to, I'm going to have to leave it there.
In reply to PM Poster (util for ease of posting / reply) by David Caughell
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |