in reply to What to do with my "Tk entry command-history" function
#!usr/bin/perl -w use strict; # Filename 'Linehist.pm' same as package name, Module in same director +y as the code you wish to call it from use Tk; package Linehist; # Package name (might go before the use Tk I'm nev +er sure ) sub history { my $entry = shift; my $cmand = shift; my $hist; if ($cmand eq "new") { my %hash; my @list; $hash{hlist} = \@list; $hash{place} = 0; my $ref = \%hash; return $ref; } else {$hist = shift;} if ($cmand eq "add") { my $string = $$entry->get; $$entry->delete('0','end'); push(@{$hist->{hlist}},$string); $hist->{place}++; } elsif ($cmand eq "up") { if ($hist->{place} <= 0) {$hist->{place} = $#{$hist->{hlist}}} else {$hist->{place}--}; $$entry->delete('0','end'); $$entry->insert('1',$hist->{hlist}[$hist->{place}]); } elsif ($cmand eq "down") { $$entry->delete('0','end'); if ($hist->{place} == $#{$hist->{hlist}}) { $hist->{place} = -1; return} $hist->{place}++; $$entry->insert('1',$hist->{hlist}[$hist->{place}]); } } 1; # Module is loaded by use or require
#!usr/bin/perl -w use stirct; use Linehist; my $entry = 'What ever you had'; Linehist->history(\$entry, 'new');
come to think of it might be something like this actuallyhistory(\$entry, 'one');
Although something in the modules may have to change to do that.use Linehist qw(history);
|
|---|