in reply to Re: Re: Posting Program
in thread Posting Program
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(" ", $q->font({-color=>'yellow'}, '<-- ' ), $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'}, ' -->' ) ); } 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'}, ' -->' ) ); } 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);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Posting Program
by Jemts (Monk) on May 26, 2002 at 16:43 UTC |