Ouch. There are many things here you need to look at, but to get you going:

Here is a quick rewrite (untested) of the above code. Please ask if there's anything you don't understand.

#!/usr/local/bin/perl -w use strict; use CGI; my $basedir = "/data1/blah.net/blah/"; my $baseurl = "http://blah.blah.net"; my $q=CGI::new(); my $tpass = $q->param('password'); my $article = $q->param('text'); my $destination = $q->param('destination'); # set $file to location of txt file my $file="$basedir$destination\.txt"; # strip out all possible SSI calls here, not below (ie, remove all com +ments) $article =~ s/<!--.*?-->//gis; # make sure destination is within parameters (allow underscores as wel +l if ($destination !~ /^\w+$/){ &filename; } # ?? only overwrite existing file? If so use -T instead # if(-e $file) if(-T $file) { open(WRITE, ">$file") || &filename; print WRITE "$line\n"; close(WRITE); } else { &filename; } sub filename{ print $q->header, $q->start_html, $q->h4("Error: You can't write to that file!"), $q->end_html; exit(0); } ###################################################################### +# #!/usr/local/bin/perl-w use strict; use CGI; my $q = CGI::new(); my $basedir = "/data1/blah.net/blahs/"; my $baseurl = "http://blah.blah.net"; my $article = $q->param('article'); my $page = $q->param('page'); my $maxlength = 43; my $next = $page+1; my $previous = $page-1; my $start = ($page-1)*$maxlength; my $finish = $page*$maxlength; my $file="$basedir$article\.txt"; open(TOP, "$basedir/top\.htm")|| &filename; my $top= join '',(<TOP>); close(TOP); open(BOTTOM, "$basedir/bottom\.htm")|| &filename; my $bottom = join '', (<BOTTOM>); close(BOTTOM); open(READ, "$file")|| &filename; my @info = (<READ>); close(READ); $length=@info; $top =~ s|</head>|<base href="http://blah.blah.net"></head>|is; print $q->header, $top; print $q->header, $q->start_html, $info[$start..$finish]; # note, this -> $info[$start..$finish]; may not work - it's late and s +eemed like a good idea :) if ( ($length>$finish) && ($page>1) ) { print $q->p("&nbsp;&nbsp;", $q->font({-color=>'yellow'}, '<--&nbsp;' ), $q->a({-href => "http://blah.blah.net/cgi-bin/article. +cgi?article=$article&page=$previous"}, 'Go to the previous page' ), $q->a({-href => "http://blah.blah.net/cgi-bin/article. +cgi?article=$article&page=$next"}, 'Continue to the next page' ), $q->font({-color=>'yellow'}, '&nbsp;-->' ) ); } elsif ( ($length>$finish) && ($page==1) ) { print $q->p({-align => 'right'}, $q->a({-href => "http://blah.blah.net/cgi-bin/article. +cgi?article=$article&page=$next"}, 'Continue to the next page' ), $q->font({-color=>'yellow'}, '&nbsp-->' ) ); } print $bottom, $q->end_html; exit(0); sub filename{ print $q->header, $q->start_html( -title => 'Article does not exist'), $q->p('Sorry, That article does not exist), $q->end_html; exit(0); }

This is by no means how I would write this, but I hope you will take the time to look up the CGI docs and use it in future. It's a lot better than trusting your own sub!

This should keep you going for now...

As to your characters per line issue, you don't state whether paragraph breaks are needed. Here's a hint anyway for the first script:

$article =~ s/\s+/ /gs; $article =~ s|([^\n]\b{0,100})|$1<br/>|gs;

hth

cLive ;-)

--
seek(JOB,$$LA,0);


In reply to Re: Posting Program by cLive ;-)
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.