bbs admin problem

R

Robin

This one's really got me stumped... the bbs files are "something.post" and
the reply files are "something2.something" the second something being the
name of the person who posted originally. What I'd like this script to do is
to remove all of the reply files that corospond to the original post file...
and when I run it it just deletes them all... I already understand why, but
how can I get this so it only deletes the corosponding files. Thanks. btw,
I'm doing this as a hobby, I study creative writing- some of my stories are
at http://www.reachcac.org/robin/stories.html

#!/usr/bin/perl

#admin.cgi for bbs.cgi v.1.0.1

require ('lib.cgi');
require ('authlib.cgi');
&data_cgivars;
$" = "";
$, = "";
&login ("bbs.cgi");
if ($FORM{'Logout'})
{
&logout ("bbs.cgi");
exit;
}
if (! ($FORM{'Submit'}))
{
&output ("Welcome to BBS Admin...");
exit;
}
if (! ($FORM{'del'}) && $FORM{'Submit'})
{
&output ("Please select a file!");
exit;
}
print ("Content-type:text/html\n\n");
opendir (BBSFILES, "BBSFILES/");
@files = readdir (BBSFILES);
closedir (BBSFILES);
foreach $file (@files)
{
if ($file ne "." and $file ne "..")
{
#opendir (BBSFILES, "BBSFILES/");
#@files2 = readdir (BBSFILES);
#closedir (BBSFILES);
unlink ("BBSFILES/$file") if ($file eq $FORM{'del'});
@sec = split (/\./, $file);a
if ($sec[1] ne "post")
{
$file =~ s/\..+//;
if (-e "BBSFILES/$file.$sec[1]")
{
unlink ("BBSFILES/$file.$sec[1]");
}
}
else
{ next; }
}
}
&output ("Your changes have been made!");
exit;



sub output
{
my ($output) = @_;
print ("Content-type:text/html\n\n");
print <<END;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>BBS ADMIN</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<div align="center">
<p><strong>BBS Admin</strong></p>
<p>$output</p>
<p>Delete Entries:</p>
<form action="admin.cgi" method="post">
<p>
<select name="del" size="7" id="del">
END

opendir (BBSFILES, "BBSFILES/");
@filesout = readdir (BBSFILES);
closedir (BBSFILES);
foreach $fileout (@filesout)
{
if ($fileout =~ /\.post/)
{
print ("<option value=\"$fileout\">$fileout</option>");
}
}

print <<END;

</select>
</p>
<p>
<input type="submit" name="Submit" value="Delete">
<input type="submit" name="Logout" value="Logout">
</p>
</form>
</div>
</body>
</html>

END

}
 
M

Marc Bissonnette

Robin said:
I want to use the code I have...

Robin;

I went through this argument that you are sinking into a couple of years
ago in this newsgroup - I asked for suggestions on how to do (whatever)
without using CGI.pm and was repeatedly told to stop wasting everyone's
time if I insisted on doing things the wrong way.

Skip ahead these past years and all of my CGI scripts use CGI.pm. Why ?
Because they (the regulars in this newsgroup) were right and I was wrong.

CGI.pm has been developed - and peer reviewed - in such a way as to
provide the most efficient method for performing the most common of CGI
related tasks.

If you think that you are improving your skills such that a potential
employer will be impressed that you can dump all your passed arguments
from a website into your own hash all by hand - instead of using CGI.pm

(ex:
use CGI;
$q = new CGI;
%in = $q->Vars;
)

then you are mistaken - Why would an employer want to be paying you to
re-invent an already solidly designed wheel for each and every single
script your write ? This is also assuming that the code you are re-
creating (that pre-exists in CGI.pm) is as secure, efficient and as fast
as the routines available within CGI.

CGI.pm is *standard* these days - it's not like you are being told to go
out and use some eccentric bit of code. It will save you *hundreds* of
hours per year in your coding by allowing you to focus on creating perl
code that does the actual work you desire to accomplish, rather than re-
writing the precursors to simply parsing and displaying the data you need
to do your work.

I suspect there are others in this NG who could give you better examples
than this, but you're really wasting your own time and that of the many
people in this NG who are *invaluable* in providing advice, providing
you're able to show a willingness to actually follow it.

You can do a google groups search on (e-mail address removed) within
comp.lang.perl.misc and you'll see that I went through this *exact*
argument - I was wrong - I admitted it - I learned - I am a better
programmer because of it.
 
R

Robin

I went through this argument that you are sinking into a couple of years
ago in this newsgroup - I asked for suggestions on how to do (whatever)
without using CGI.pm and was repeatedly told to stop wasting everyone's
time if I insisted on doing things the wrong way.

Skip ahead these past years and all of my CGI scripts use CGI.pm. Why ?
Because they (the regulars in this newsgroup) were right and I was wrong.

CGI.pm has been developed - and peer reviewed - in such a way as to
provide the most efficient method for performing the most common of CGI
related tasks.

If you think that you are improving your skills such that a potential
employer will be impressed that you can dump all your passed arguments
from a website into your own hash all by hand - instead of using CGI.pm

(ex:
use CGI;
$q = new CGI;
%in = $q->Vars;
)
thanks marc, I like what you said about cgi.pm being standard, I like all
the stuff u said actually. I'll try to shut up.

peace,
-Robin
 
M

Marc Bissonnette

Robin said:
thanks marc, I like what you said about cgi.pm being standard, I like
all the stuff u said actually. I'll try to shut up.

It's not so much that people are telling you to shut up - it's more along
the lines of if you're going to come in here and ask for advice, then
have the good graces to follow - or at least try - the advice.

It's sorta kinda like an apprentice carpenter telling his mentor "I'm
going to cut this board with this hammer - how to I do it ?" And the
mentor replying "No, use this saw, instead". - If you insist on using the
hammer to cut the board, eventually the mentor will just give up and walk
away, no matter how many questions you ask.

Out of curiosity, do you posess the book "Learning Perl", 3rd edition, by
Randal Schwartz and Tom Phoenix ?

http://www.oreilly.com/catalog/lperl3/

This is a must have for a starting point.
When you've gone through that two or three times, move on to
"Programming Perl, 3rd Edition
By Larry Wall, Tom Christiansen, Jon Orwant"
http://www.oreilly.com/catalog/pperl3/

Go through as much of that as you can and practice, practice, practice.

For me, once past those two (And I don't claim to have mastered the
second, by far - I still pick it up to learn what I need at a given point
in time), I moved on to

Managing & Using MySQL, 2nd Edition
By George Reese, Randy Jay Yarger, Tim King
http://www.oreilly.com/catalog/msql2/

for a while, because perl works beautifully with it, then came back to

Mastering Regular Expressions, 2nd Edition
By Jeffrey E. F. Friedl
http://www.oreilly.com/catalog/regex2/

This book is where you'll learn a lot of the power of Perl, IMO.

For the CGI.pm stuff, a cursory search turns this up as a decent starting
place:

http://stein.cshl.org/WWW/software/CGI/
 
I

Iain Chalmers

Marc Bissonnette said:
For me, once past those two (And I don't claim to have mastered the
second, by far - I still pick it up to learn what I need at a given point
in time), I moved on to

Managing & Using MySQL, 2nd Edition
By George Reese, Randy Jay Yarger, Tim King
http://www.oreilly.com/catalog/msql2/

I feel I need to comment that this is by far the _worst_ OReilly book
I've ever bought...

I'd suggest
Programming the Perl DBI
By  Alligator Descartes ,Tim Bunce
http://www.oreilly.com/catalog/perldbi/

is a far more useful Perl book (if you already know MySQL), and

MySQL
by Paul Dubois
http://www.newriders.com/books/product.asp?product_id={FC784549-C0F6-44
BC-8D69-393B557CDF40%7D

if you want to learn about how to use MySQL (rather than just how to use
it from perl).

Managing & Using MySQL (though, admittedly, I've got the first edition)
is little more than a printed copy of a bunch of out of date MySQL
documentation with maybe 3 or 4 chapters of original stuff...

big
 
T

Tad McClellan

Even the beloved O'Reilly makes mistakes.

I feel I need to comment that this is by far the _worst_ OReilly book
I've ever bought...


George Reese has a reputation hereabouts.

He trolled here with vigor some years ago.

Message-ID: <[email protected]>

Message-ID: <[email protected]>


I expect that a book written by a troll would be suboptimal.
 
M

Marc Bissonnette

I feel I need to comment that this is by far the _worst_ OReilly book
I've ever bought...

I'd suggest
Programming the Perl DBI
By  Alligator Descartes ,Tim Bunce
http://www.oreilly.com/catalog/perldbi/

is a far more useful Perl book (if you already know MySQL), and

MySQL
by Paul Dubois
http://www.newriders.com/books/product.asp?product_id={FC784549-C0F6-
44 BC-8D69-393B557CDF40%7D

if you want to learn about how to use MySQL (rather than just how to
use it from perl).

Managing & Using MySQL (though, admittedly, I've got the first
edition) is little more than a printed copy of a bunch of out of date
MySQL documentation with maybe 3 or 4 chapters of original stuff...

Hrm, that's good to know - The Reese book got me started, though just
about all my MySQL learning these days comes from
http://www.mysql.com/documentation/ along with Usenet and Google.

The Reese threads are making for entertaining afternoon reading, however
:)

Thanks for the correction/heads up.
 
R

Robin

I finally got it working, now using subs called without "ampersands" thanks
to whoever corrected me... is this a top post or something else? I read some
articles on top posting btw, so I'm more informed...

peace,
-Robin
 
W

Walter Roberson

This line would be top-posting. [And I apologize to others... I only
do it for demonstration.]

:I finally got it working, now using subs called without "ampersands" thanks
:to whoever corrected me... is this a top post or something else? I read some
:articles on top posting btw, so I'm more informed...

This line isn't top-posting. Nor was your most recent post. Top-posting
is posting on the top of whatever you are replying to.
 
T

Tintin

Robin said:
I finally got it working, now using subs called without "ampersands" thanks
to whoever corrected me... is this a top post or something else? I read some
articles on top posting btw, so I'm more informed...

For some definition of "working".

I don't know why you are still confused about top posting. You've been
given plenty of articles to read and you can see perfect examples everyday
in this group.

The next thing you need to learn is context and references. Please re-read
Tad's posting guidelines *again*
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top