if ($optimize_history) {
# remove duplicities from history
my @history = $term->GetHistory($file);
my %history = map {$_ => 1} @history;
my @new_history = ();
for (reverse @history) { # in reverse order
if ($history{"$_"}) { # if not remembered yet
unshift @new_history, $_; # remember history line
delete $history{"$_"}; # and remove it
}
}
$term->SetHistory(@new_history); # set history to new list
$term->WriteHistory($file); # save history
} else {
# only add new line to the history file
$term->WriteHistory($file);
}
####
if ($optimize_history) {
my @history = $term->GetHistory($file);
my %history;
# eliminate duplicates in history and keep only the most recent
for(my $i=scalar(@history)-1;$i>=0;$i--) {
$_ = $history[$i];
!$history{$_} ? $history{$_}=1 : splice(@history,$i--,1);
}
$term->SetHistory(@history); # set history to new list
}
$term->WriteHistory($file); # save history
####
$history{$_} ? splice(@history,$i--,1) : $history{$_}=1;
####
Can't modify splice in scalar assignment at ./history.pl line 35, near "1;"
Execution of ./history.pl aborted due to compilation errors.