Home: Perl Programming Help: Beginner:
Deleting an item from a list



srehal
Deleted

Mar 31, 2000, 7:17 AM


Views: 2011
Deleting an item from a list

I have a list of documents on a page and I want the user to input the number associated with a particular document in a text field and then press the delete button.This should call a cgi script which should display to the user a new list minus the deleted document.
I have this code so far:
$NumberToDelete=$FORM{"numbertext"};

#opens a file to read
#checks to see if the number entered is the same as a number in the .csv file
#if it is then we want to delete it

#open(READONLY,"<document.csv");
# if ($NumberToDelete==Number) {
# print ("$Number,$Description,$Author,$Date,$Document\n");
# }
# print("You have entered a number that does not belong to an existing

#document");

open(READONLY,"<document.csv");
if ($NumberToDelete==Number) {
open(NEWFILE, ">>../NewDocument.csv");
print "$Number,$Description,$Author,$Date,$Document\n";
}
print("You have entered a number that does not belong to an existing

document");

close(NEWFILE);
close (READONLY);


Cure
User

Mar 31, 2000, 3:47 PM


Views: 2011
Re: Deleting an item from a list

Hi

This will delete a user in your database.

$NumberToDelete=$FORM{"numbertext"};

open(READONLY,"document.csv");
open(NEWFILE, ">newdocument.csv");

while (<READONLY> ) {

my ($Number,$Description,$Author,$Date,$Document)=split/,/,$_;

print 'you have been succedfully deleted from our database' if($NumberToDelete==$Number);


if(!($NumberToDelete==$Number)) {

push @cure,$_;
}
}

print NEWFILE @cure;

close(NEWFILE);
close (READONLY);


Cure