Please Check My Code...
This code is supposed to delete a particular line from a file, delete a file, and delete the directory that the file was in.
sub delete {
open(MEMBERS, "$data_path/members.txt") or die "Cannot open $data_path/members.txt to read: $!";
if ($flock eq "y") {
flock MEMBERS, 2;
}
@members = <MEMBERS>;
close(MEMBERS);
chomp @members;
$linecount = "0";
foreach $line (@members) {
($membernum, $membername, $email) = split(/\|/, $line);
$linecount++;
if ($membernum eq $FORM{'user'}) {
splice(@members,$linecount,1);
unlink("$data_path/$membernum/info.txt");
rmdir("$data_path/$membernum");
print "<FONT FACE=\"Verdana\">User $membername has been deleted.</FONT><BR>\n";
}
}
}
For some reason, it doesn't do anything. Can anyone help?
Thanks!
--Edge
Matt@Ikonboard posted this at 21:48 — 15th January 2001.
They have: 16 posts
Joined: Jan 2001
my $member_name;
open MEMBERS, "<$data_path/members.txt" or die "Cannot open $data_path/members.txt to read: $!";
open TEMP, ">$data_path/members.tmp";
flock MEMBERS, 2 if $flock eq 'y';
flock TEMP, 2 if $flock eq 'y';
select (TEMP);
while (<MEMBERS>) {
chomp;
@_ = split /\|/;
if ($_[0] eq $FORM{'user'}) {
$member_name = $_[1];
unlink($data_path/$_[0]/info.txt) or die $!;
rmdir($data_path/$_[0]) or die $!;
} else {
print TEMP $_,"\n";
}
}
close MEMBERS;
close TEMP;
rename ("$data_path/members.tmp", "$data_path/members.txt");
select (STDOUT);
print "<FONT FACE=\"Verdana\">User $member_name has been deleted.</FONT><BR>\n";
This assumes that the line to be deleted is in the file you are opening and checking for a match.
my $friends = qq[=:Jilly , Andrew , Peter & Harry:=];
print &welcome($friends), "2"; my @home;
sub welcome{my $s=shift; $s=~s{^(=\(.+?)(\:=)$}
{$_=$2;@home=split/[&,]/;}esgx;$friends= join'me',@home;
$friends=~s{(\A|\S|\s+)([A-Z]).+?(\s|\Z)}{$2}sge;my$c=-1;
$friends=~s{(me|\Z)}{++$c;@_=(qw|ust nother erl acker|);qq!$_[$c] !;}eg; $friends}
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.