I've returned to this post at the close of my semester in college.

I've read through a book on CGI/Perl that was an introductory book, as well as through the first chapter and a bit of Programming Perl. Because I don't have too much reading under my belt, the code for this is a little sloppy.

I rewrote the script (even after Jeffa posted a good one) for two reasons: One, that I didn't understand Jeffa's script, and Two, that it's important that the script output as text/plain, so that it will be easy to cut and paste into the post window (otherwise the paragraph tags disappear). I made sure to take out the break tags, too!

It would have been nice, if the following line worked (which would have made my code a lot simpler):

split /\n{2,}/, $inputed_text;

However, that doesn't work, hence the messy code for determining what a paragraph is:

#!/usr/bin/perl -w use strict; use CGI qw(:standard -debug); # Perlmonks.org Poster, by David Caughell, grasp_the_sun@yahoo.co.uk # Converts simple text into text that can be cut and paste into PM pos +ts print "Content-type: text/plain\n\n"; my $text = param('FPost'); my @sections = split('code'.'>', $text); # get rid of leftovers from code tags for (@sections) { chop if /\/$/; chop if /<$/; } for (0 .. $#sections) { unless ($_ % 2) { my @lines = split /\n/, $sections[$_]; my @paragraphs = (''); for (@lines) { if (length $_ <= 1) { push(@paragraphs,'') if length($paragraphs[$#paragraphs]); } $paragraphs[$#paragraphs] .= $_ if length $_ > 1; } pop(@paragraphs) unless length $paragraphs[$#paragraphs]; print "<P>\n$_\n</P>\n\n" for @paragraphs; } else { print '<code'.">\n$sections[$_]</code".">\n\n"; } }

Dave.

$scratchpad_public = 0 unless $scratchpad;


In reply to Re: Re: PM Poster (util for ease of posting / reply) by David Caughell
in thread PM Poster (util for ease of posting / reply) by David Caughell

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.