I suppose you could have an input loop that would be checking to see if you've typed a '\t', which would then iterate through your opendir list with a little regex for filtering what you've already got... Probably use Term::ReadKey.
#! /usr/bin/perl -w
use Term::ReadKey;
# make STDOUT hot
$| = 1;
$string = '';
$done = 0;
# get your dir listing
opendir($dh, '.');
@dir = sort readdir($dh);
closedir $dh;
# input loop
while (!$done) {
# read a key
while (defined ($key = ReadKey(-1))) {
# if it's a tab, get the next thing in the directory
if ($key =~ /\t/) {
# treat dir as circular list
$cur = shift(@dir);
# 'clear' the input
print "\b" x (length($string));
print " " x (length($string));
print "\b" x (length($string));
$string = $cur;
push(@dir, $cur);
}
# return means we're done
elsif ($key =~ /\r/) {
$done = 1;
last;
}
# otherwise add to input string
else {
$string .= $key;
# don't forget to clear to keep things looking normal
print "\b" x (length($string) - 1);
}
print $string;
}
}
print "\nyou have selected: $string\n";
Yeah, it's a little funky. But I'm pretty sure it meets your requirements =D
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.