in reply to Simulating input history without Term::Readline::Gnu
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.
-Michael
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Simulating input history without Term::Readline::Gnu
by ackerleytng (Initiate) on Jul 16, 2013 at 19:02 UTC |