here is the code for the program that reads the textareea and prints it into a file:
#!/usr/local/bin/perl ############################## #Post article of information # # by Matthew Manela # ############################## require 'subparseform.lib'; # sub parsing $basedir = "/data1/blah.net/blah/"; $baseurl = "http://blah.blah.net"; &Parse_Form; print "Content-type: text/html\n\n"; $tpass=$formdata{password}; $article=$formdata{text}; $destination=$formdata{destination}; #the source of the file to write to @info=split(/\n/,$article); # set $file to location of txt file $file="$basedir$destination\.txt"; # make sure destination is within parameters if($destination=~/^([a-zA-Z])+$/){ &main; }else{ &filename; } sub main{ if(-e $file){ open(WRITE, ">$file")|| &filename; foreach $line (@info){ print WRITE "$line\n"; } close(WRITE); }else{ &filename; } sub filename{ print"You can't write to that file!\n"; exit; }
and the code of the program that shows the info 45 lines at a time:
#!/usr/local/bin/perl # Get article form link and display # by Matthew Manela require 'subparseform.lib'; # sub parsing $basedir = "/data1/blah.net/blahs/"; $baseurl = "http://blah.blah.net"; &Parse_Form; print "Content-type: text/html\n\n"; $article=$formdata{'article'}; $page=$formdata{'page'}; $maxlength=43; $next=$page+1; $previous=$page-1; $start=($page-1)*$maxlength; $finish=$page*$maxlength; &main; sub main{ $file="$basedir$article\.txt"; open(TOP, "$basedir/top\.htm")|| &filename; @top=<TOP>; close(TOP); open(BOTTOM, "$basedir/bottom\.htm")|| &filename; @bottom=<BOTTOM>; close(BOTTOM); open(READ, "$file")|| &filename; my @info = grep { !/^\s*$/ } <READ>; chomp(@info); close(READ); $length=@info; foreach $part (@top) { if ($part=~/^<\/head>$/){ print"<base href=\"http://blah.blah.net\"></head>\n"; }else{ print"$part\n"; } } for($i=$start;$i<$finish;$i++){ if ($info[$i]=~ m/<!--\#include/) { }else{ print"$info[$i]\n"; } } if (($length>$finish)&&($page>1)){ print"<p align=left>&nbsp&nbsp<font color=yellow><--</font>&nbsp<a hre +f=\"http://blah.blah.net/cgi-bin/article.cgi?article=$article&page=$p +revious\">Go to the previous page</a><a href=\"http://blah.blah.net/c +gi-bin/article.cgi?article=$article&page=$next\">Continue to the next page</a>&nbsp<font color=yellow>--></font>&nbsp&nb +sp</p>\n"; }elsif(($length>$finish)&&($page==1)){ print"<p align=right><a href=\"http://blah.blah.net/cgi-bin/article.cg +i?article=$article&page=$next\">Continue to the next page</a>&nbsp<fo +nt color=yellow>--></font>&nbsp&nbsp</p>\n"; } foreach $thing (@bottom){ print"$thing\n"; } } sub filename{ print"<html><head><title>Article does not exist</title></head><body>\n +"; print"Sorry, That article does not exist.<br>\n"; print"</body></html>"; exit; }


Jemts

"If you're traveling in a time machine, and you're eating corn on the cob, I don't think it's going to affect things one way or the other. But here's the point I'm trying to make: Corn on the cob is good, isn't it."

In reply to Re: Re: Posting Program by Jemts
in thread Posting Program by Jemts

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.