PDA

View Full Version : OT: Perl



Sharky
04-08-2002, 07:39 PM
If anyone is good at programming in Perl/CGI please gimme an email asap i'm havin a nightmare.

eshakarchi@hotmail.com

cheers

Sharky
04-08-2002, 07:42 PM
i'm on msn messinger 24/7 now too

prana
04-08-2002, 09:22 PM
perhaps post the question here... ? but I am not good at it, sorry man.

Sharky
04-09-2002, 06:39 AM
I am doing a comp sci degree and i have under 3 weeks to design an
online library system, where you have to be able to search for books in a database, get them out, the admin has to be able to add books to the db, remove, edit records etc, each user has to have his own account, be informed of fines, yadda yadda. And it has to be web based.

I am having a nightmare. I really need help but there is no one to talk to or turn to. If i don't hand this in soon (i have to write it up which is worth 70%) i will fail my degree.

At the moment i have only done the following: created a flatfile database, and made scripts so that online, you can add to a database. That is all i have done! I am so behind! I am trying to make scripts that delete individual records, and also edit records, but i can't do it. I found scripts online to show me how it's done, but when i use them they delete the whole file!!!!

The code to delete a singe record is here:

#!/usr/local/bin/perl

#######################################
# Define the variables for the script #
#######################################
$database='books.db';

############################
# Get data from GET & POST #
############################
require "cgi-lib.pl";

&ReadParse(*input);

#################################################
# Get the origional database data & buffer data #
#################################################
open (ORGDB,"<$database");
@ODB=<ORGDB>;
close (ORGDB);


################################################## ###############
# Open the database to write data, changing the neccesary lines #
################################################## ###############
if ($input{'action'} eq 'delete'){
open (DATABASE,">$database");
@DB=<DATABASE>;
foreach $rec (@ODB){
chomp($rec);
($title,$author,$classmark,$type,$status)=split(/\|/,$rec);
if ($title eq $input{'title'} && $author eq $input{'author'} && $classmark eq $input{'classmark'} && type eq $input{'type'} && $status eq $input{'status'}){
print DATABASE "";
}else{
print DATABASE "$title|$author|$classmark|$type|$status\n";
}
}
close (DATABASE);
}





I mean, this is barely my code, i just copied it, cos i just ran out of ideas man. By the way it has been text wrapped. It recieves the info (input) from another file which is here:

#!/usr/bin/perl

#####################
#This reads the database, and also has links to delete and edit the


$data_file="books.db";

open(DAT, $data_file) || die("Apoligies - the library system is temporarily down. Please try again soon");
@raw_data=<DAT>;
close(DAT);

print "Content-type: text/html\n\n";
print "
<html>
<head><title> Library Database </title>
<body>
<font face='Arial' size='2'>
<h1><i>Database View</i></h1>
<table width='100%' border='1'>
<tr><td bgcolor='#F2C973'><font size='2'>Actions</font></td><td bgcolor='#F2C973'><font size='2'>Title</font></td>
<td bgcolor='#F2C973'><font size='2'>Author</font></td>
<td bgcolor='#F2C973'><font size='2'>Classmark</font></td>
<td bgcolor='#F2C973'><font size='2'>Type</font></td>
<td bgcolor='#F2C973'><font size='2'>Status</font></td></tr>
";

foreach $book (@raw_data)
{
chop($book);
($title,$author,$classmark,$type,$status)=split(/\|/,$book);

print "<tr><td><font size='2'><a href='edit_record2.cgi?title=$title&author=$author&classmark=$classmark&type=$type&status=$status'>Edit</a> - <a href='edit6.cgi?action=delete&title=$title&author=$author&classmark=$classmark&type=$type&status=$status'>Delete</a></font></td>
<td><font size='2'>$title</font></td>
<td><font size='2'>$author</font></td>
<td><font size='2'>$classmark</font></td>
<td><font size='2'>$type</font></td>
<td><font size='2'>$status</font></td></tr>\n";

}

print "</BODY></HTML>";



When you goto try to delete a record ti deletes them all. Like i say, i'm just using the script off the net, which works, all i did was change the variable names.

I really can't go into the depth of my problems, i need help :(

If you have msn messinger please please please look me up on that man.

Thanks in advance for anyhelp you might be able to give me

Eddie Shakarchi

If anyone knows of where i can go to get help, anybody online, any forums please say cos i got no where to turn and i'd rather not fail my degree.

Cheers

Sharky
04-09-2002, 06:43 AM
yeah, that's right 3 weeks. which means i gotta do it in like a week and a half so that i can start the write up.

i've failed already :(

Mr Punch
04-09-2002, 06:45 AM
Thanks Sharky, with your provactive thread titles again... and I thought you were talking about the knitting stitch...:eek:

ewallace
04-09-2002, 06:52 AM
Does it have to be done in perl? If so, would it help you at all if you saw it in another language like asp?

Sharky
04-09-2002, 06:54 AM
Maybe ewallace. I was gonna do it in asp but everyone else did it in perl. I need any help at all man, anything.

Cheers

ewallace
04-09-2002, 06:55 AM
Does it have to be done in perl?

Sharky
04-09-2002, 06:57 AM
no man not at all - but i've started in perl and i'm on a mac (no nt).

but no it doesn't man, any ideas?

ewallace
04-09-2002, 07:00 AM
Does it have to work? :) I can help you out if you want it in asp (JScript). Shouldn't take more than a couple days to do.

ewallace
04-09-2002, 07:02 AM
Go to chat. http://www.kungfuonline.com/chat.html

Sharky
04-09-2002, 07:08 AM
man, that chat thing crashes my computer everytime!

got msn messenger or aol instant messenger?

msn: eshakarachi@hotmail.com

aol: PreciseLyricalOp

pwitty pweese

scotty1
04-09-2002, 08:51 AM
"Does it have to work? I can help you out if you want it in asp (JScript). Shouldn't take more than a couple days to do."

Aw, you guys....:)

fa_jing
04-09-2002, 02:48 PM
don't know PERL, man. Why are you studying this, seems like a highly specialized language?? anyhoo, check out www.perl.com and www.perl.org

good luck sharkinator!!

fa_jing
04-09-2002, 02:50 PM
P.S. maybe the mods will agree to ban you from KFO temporarily so you can get some work done! :D :)

Sharky
04-09-2002, 05:16 PM
i'm studying it cos i got to :((

Kumkuat
04-09-2002, 06:11 PM
Instead of flat files, can't you use SQL?

Anyway, I don't understand what you mean by deleting a record. How is the data record stored in the flat file?

Colin
04-11-2002, 07:25 AM
Yea, maybe get the search stuff done in SQL. You can incorporate it into your Perl script, I think! Coz I use Shell(Korn) for most of my scripts, with a bit of SQL.

I'm so glad the college sh!t is all behind me now!

Good luck.

Colin.......

Sharky
04-11-2002, 07:27 AM
it's much harder to do it in sql in perl. it much easier to use a flat file for a relatively small database.

i'm getting er, "help" (ahem?) from ewallace to do it in ASP now.

Andrew
04-12-2002, 03:51 AM
Yup, I know Perl. If you want a start get the Perl Cookbook,
there's a worked example there. Also you should not use cgi-lib.pl.
This is very 1999. Use CGI.pm also Look at the GDBM.pm module,
then you can bind the entries to a hash. Never put
HTML in your script, always place it in a separate file.
If you want to be really clever, use a directory structure.
If you can afford to wait, I might be able to write you a
'proper' script.

Andrew