Skip to content

Commit

Permalink
Applied Nick Williams' patch to remove newlines from history read from
Browse files Browse the repository at this point in the history
a file and to truncate the loaded history to the maximum number of
lines it should maintain.
  • Loading branch information
rcaputo committed Jul 27, 2006
1 parent 7e13956 commit 9a4bca5
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/POE/Wheel/ReadLine.pm
Expand Up @@ -1151,12 +1151,15 @@ sub history_truncate_file {
$file ||= "$ENV{HOME}/.history";
open(HIST, $file) or return undef;
my @hist = <HIST>;
chomp(@hist);
close(HIST);

if ((scalar @hist) > $lines) {
open(HIST, ">$file") or return undef;
if ($lines) {
splice(@hist, -$lines);
print HIST @{$self->[SELF_HIST_LIST]} = @hist;
splice(@hist, 0, (scalar @hist)-$lines);
@{$self->[SELF_HIST_LIST]} = @hist;
print HIST join("\n", @hist) . "\n";
} else {
@{$self->[SELF_HIST_LIST]} = ();
}
Expand Down

0 comments on commit 9a4bca5

Please sign in to comment.