in reply to How do i delete my guestbook's data ?
Updatemy $data = "/path/to/file.txt"; # Path to the datafile. open(FILE,"+<$data") || die("Can't open database - $!\n"); #Reads the + file, you can use <$data, in fact, and <$data should be used. chomp(@lines = <FILE>); #Gets rid of newlines close(FILE); # Closes the file my @line; foreach my $line (@lines) { #Foreach line in the file. my ($usernumber,$username,$guestbookinfo) = split(/\__/, $line); # We + will split it up using __ as our delimiter. # The new values of each field (in order) will be $usernumber,$userna +me,$guestbookinfo. $line[$usernumber][0] = $username; # perldoc PerlDSC. This is a mul +tidimensional array. It is used used in order to organize our array, + using the usernumber, and 0 for user name... $line[$usernumber][1] = $guestbookinfo; # Or 1 for the information in the guestbook. } # If we were to call $line[0][1], we would be given the value of the g +uestbook information of the user who lies in the first line of the da +ta file! open(FILE,">$data") || show_die("Can't open database - $!\n"); # Thi +s was wrong last time. It should be >, as we're going to completely +rewrite the file. for my $family (reverse(1 .. $#line) ) { #the @line array has a certa +in amount of values in it (0 to some number), $#line will give us the + amount of values. # By reversing 1 .. the amount of values, we can print everything int +o the data file, just like you wanted it to be printed (with the high +est first.) unless ($line[$family][0] eq "$user_to_delete") {print FILE $family."_ +_".$line[$family][0]."__".$line[$family][1]."\n";} # Unless the username ($line[$family][0]) (refer to the foreach code) + is the username we wish to delete, which you will have to assign usi +ng CGI.pm or some form parser before this starts, we print out all th +e information. } #The for statement will go backwards through each line, until we hit t +he first line. Since you started usernumber at 1, we end the for loo +p at one. close(FILE); #Close the file, and we're done!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: How do i delete my guestbook's data ?
by 12monkey (Initiate) on Mar 30, 2002 at 01:16 UTC | |
|
Re: Re: How do i delete my guestbook's data ?
by 12monkey (Initiate) on Mar 30, 2002 at 01:19 UTC | |
|
Re: Re: How do i delete my guestbook's data ?
by 12monkey (Initiate) on Apr 03, 2002 at 09:00 UTC |