The modules mentioned above can be useful, and Term::UI::History might be worth looking at.
A simple method of recording history might be to just push the input to an array, for example:
#!/usr/bin/perl use strict; use warnings; my @history; my $text; my $x; print STDERR "Enter text ('q' to quit): "; $text = <STDIN>; chomp $text; push (@history, "$text\n"); while ($text ne 'q') { print STDERR "Enter text ('q' to quit): "; $text = <STDIN>; chomp $text; push (@history, "$text\n"); } my $numberOfHistoryItems = @history; print STDERR "For history, press 'h', else quit:"; my $history = <STDIN>; chomp $history; if ($history eq "h") { for($x = 0; $x < $numberOfHistoryItems; $x += 1) { print STDOUT "$history[$x]" if $numberOfHistoryItems > +0; } print STDOUT "No history items\n" if $numberOfHistoryItems == +0; }
Although admittedly, that might get tedious and unwieldy if your script is long.
-MichaelIn reply to Re: Simulating input history without Term::Readline::Gnu
by mtmcc
in thread Simulating input history without Term::Readline::Gnu
by ackerleytng
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |