Sorry for all my questions I ask..
but I am stuck working to delete a line from a flat file db..
I use this code right now but it always deletes the last line or first line and not any other one.
sysopen(FILE, "$datapath/members/carts/$FORM{'username'}.txt", O_RDWR) or die "Can't open: $!";
flock(FILE, LOCK_EX);
$ItemIndex = "$FORM{'item'}|$FORM{'num'}|$FORM{'price'}|$FORM{'desc'}|$FORM{'quant'}|";
@FileContents = <FILE>;
@DeletedItem = splice(@FileContents, $ItemIndex, 1);
seek(FILE, 0, 0) or die "Can't return to beginning: $!";
truncate(FILE, 0) or die "Can't truncate file to zero length: $!";
print FILE @DeletedItem;
flock(FILE, LOCK_UN);
close(FILE);-------------
Jeremy
http://lc.crashinto.com - Crashinto Learning Central
but I am stuck working to delete a line from a flat file db..
I use this code right now but it always deletes the last line or first line and not any other one.
Code:
use Fcntl qw(:DEFAULT :flock); sysopen(FILE, "$datapath/members/carts/$FORM{'username'}.txt", O_RDWR) or die "Can't open: $!";
flock(FILE, LOCK_EX);
$ItemIndex = "$FORM{'item'}|$FORM{'num'}|$FORM{'price'}|$FORM{'desc'}|$FORM{'quant'}|";
@FileContents = <FILE>;
@DeletedItem = splice(@FileContents, $ItemIndex, 1);
seek(FILE, 0, 0) or die "Can't return to beginning: $!";
truncate(FILE, 0) or die "Can't truncate file to zero length: $!";
print FILE @DeletedItem;
flock(FILE, LOCK_UN);
close(FILE);
Jeremy
http://lc.crashinto.com - Crashinto Learning Central