Simple answer is yes but modules are pretty easy.
You'd prob want more then just one function though to make a module. But if it's just for personal use then something like the following would work:
#!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

Then to call it.
#!usr/bin/perl -w use stirct; use Linehist; my $entry = 'What ever you had'; Linehist->history(\$entry, 'new');

There are of course alternative ways of calling it. And there's definitely a way of exporting it so you can just call
history(\$entry, 'one');
come to think of it might be something like this actually
use Linehist qw(history);
Although something in the modules may have to change to do that.
Hope that helps.

- John

In reply to Re: What to do with my "Tk entry command-history" function by binf-jw
in thread What to do with my "Tk entry command-history" function by halfcountplus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.