tie @log, 'Tie::File', $logfile or displayError("could not open logfile"); while ($some_condition) { #do some other stuff, and unshift @log, $info_to_be_logged; } # find out how long the logfile is, and truncate it $length = @log; $truncate = $length - 150; if ($truncate > 0) { $#log -= $truncate; } untie @log; #### sub delete_threads_from_file { $logfile = "$htdocs${bbs_location}/$removed_log"; tie @log, 'Tie::File', $logfile or displayError("could not open logfile"); local($file, $delete_hash) = @_; local(*FILE); local($new_content); if ((open(FILE, "$file"))) { while($line = ) { if ($line =~ //) { local($id) = ($line =~ //)[0]; $should_delete = 0; foreach $delete_id (keys(%{$delete_hash})) { # look for exact id matches if ($id eq $delete_id) { $should_delete = 1; # add this id to the removed.log unshift @log, $delete_id; } # if the delete_id(message) is a topic message, # remove all its responses local($d_thread_id,$d_message_id) = split(/_/, $delete_id); local($thread_id,$message_id) = split(/_/, $id); if (($d_thread_id == $d_message_id)&&($thread_id == $d_thread_id)) { $should_delete = 1; # if this is a response to a removed topic, # add it to the removed.log if ($id ne $delete_id) { $should_delete = 1; unshift @log, $id; } } } if (! $should_delete) { # this id is NOT in our list of ids to delete, so keep it $new_content .= $line; } } else { $new_content .= $line; } } close(FILE); # find out how long the logfile is, and truncate it $length = @log; $truncate = $length - 150; if ($truncate > 0) { $#log -= $truncate; } untie @log; } ### ### modify the file ### if ((open(FILE, "> $file"))) { print FILE $new_content; close(FILE); } }