Hi, everyone. I've written a simple message board and all works well, but I would like to have any posts that are replied to, go to the top line in my flat file. As it stands, the method below updates the $replies just fine and all, but I can't figure out how to make the update "AND" move the "UPDATED" line to the "TOP".
open(DAT, "+<$dir/$db") || die error( $! );
flock(DAT, LOCK_EX) || die error( $! );
my @dat = <DAT>;
seek(DAT, 0, 0) || die error( $! );
foreach (@dat) {
($thread,$subject,$name,$replies,$date) = split(/\|/);
if (param('thread') == $thread) {
$replies++;
print DAT "$thread|$subject|$name|$replies|$date";
} else { print DAT $_; }
}
close(DAT) || die error( $! );
Below is how it appears "before" updating FIRST POST with the above code:
3|THIRD POST|Robert|0|Sat Jun 26 13:54:25 2004
2|SECOND POST|Jerry|0|Sat Jun 26 13:54:02 2004
1|FIRST POST|Susan|0|Sat Jun 26 13:53:35 2004
And then after updating, it looks like below:
3|THIRD POST|Robert|0|Sat Jun 26 13:54:25 2004
2|SECOND POST|Jerry|0|Sat Jun 26 13:54:02 2004
1|FIRST POST|Susan|1|Sat Jun 26 13:53:35 2004
This is how I would like it to read: (the newly updated line at the top)
1|FIRST POST|Susan|1|Sat Jun 26 13:53:35 2004
3|THIRD POST|Robert|0|Sat Jun 26 13:54:25 2004
2|SECOND POST|Jerry|0|Sat Jun 26 13:54:02 2004
Is it possible to have this happen? If so, can anyone see a solution?
open(DAT, "+<$dir/$db") || die error( $! );
flock(DAT, LOCK_EX) || die error( $! );
my @dat = <DAT>;
seek(DAT, 0, 0) || die error( $! );
foreach (@dat) {
($thread,$subject,$name,$replies,$date) = split(/\|/);
if (param('thread') == $thread) {
$replies++;
print DAT "$thread|$subject|$name|$replies|$date";
} else { print DAT $_; }
}
close(DAT) || die error( $! );
Below is how it appears "before" updating FIRST POST with the above code:
3|THIRD POST|Robert|0|Sat Jun 26 13:54:25 2004
2|SECOND POST|Jerry|0|Sat Jun 26 13:54:02 2004
1|FIRST POST|Susan|0|Sat Jun 26 13:53:35 2004
And then after updating, it looks like below:
3|THIRD POST|Robert|0|Sat Jun 26 13:54:25 2004
2|SECOND POST|Jerry|0|Sat Jun 26 13:54:02 2004
1|FIRST POST|Susan|1|Sat Jun 26 13:53:35 2004
This is how I would like it to read: (the newly updated line at the top)
1|FIRST POST|Susan|1|Sat Jun 26 13:53:35 2004
3|THIRD POST|Robert|0|Sat Jun 26 13:54:25 2004
2|SECOND POST|Jerry|0|Sat Jun 26 13:54:02 2004
Is it possible to have this happen? If so, can anyone see a solution?