"Chas. Owens" <[email protected]> writes:
>> How big of a chore would it be to include code into the script that
>> creates some kind of editor like environment and allows bash style
>> completion?
>>
>> I'm a very low level perl coder.. and will need pointers to some clues
>> about how to get this done, and incorporated into my scripts.
>>
>> In shell scripting, at least with bash, taking input from user is done
>> with `read line' but you can say 'read -e line' and the input is
>> suddenly done with bash completion.. and I think a few other niceties.
>>
>> Is there something similar in perl?
> snip
>
> Take a look at [Term::Readline][1], [Term::Readline::GNU][2], and
> [Term::Readline::Perl][3].
I'm sad to say after installing Term::ReadLine::Gnu and looking at the
the 1014 lines of perldoc Term::ReadLine::Gnu..
I was left with no real idea as to what one might put in a script to create
an editor like environment when answering <STDIN>.
I didn't even feel I'd learned enough to try a test or two.
Maybe a simple example would help:
I've included an edited piece of one of my homeboy scripts that takes
input.
Can you show a simplified example of how I might add an editor like
environment for the input?
cat example.pl
------- 8< snip -------- ------- 8< snip --------
#!/usr/local/bin/perl
use strict;
use warnings;
my $outfile = './outfile';
print <<EOM;
To write a memo to the continuing log <$outfile>,
just type the memo. When finished, type a dot (.)
on a line by itself and hit <ENTER> to complete your input.
NOTE: We will take input until hell freezes over if you
don't type a `.' (dot) on a line by itself followed by <ENTER>
to conclude your input.
(Note: In our next script we hope to do this same feat but
offer an editor like environment for your use while
inputting your data.)
EOM
open(OUTFILE, "+>>$outfile") or die "Cannot open <$outfile>: $!";
my $cnt = 0;
my @input;
## There may be other ways to do this but the next section does this:
## If `quit' is typed on a line by itself we abort.
## If `.' (dot) is typed on a line by itself we exit this while loop
LINE: while (<STDIN>){
$cnt++;
last LINE if(/^\.$/);
if($_ =~ /^q$/){
print "You've typed `q'<ENTER> (a quit symbol) .. aborting ...\n";
exit;
}
if($cnt == 1 && $_ eq "\n"){
print "You've typed <nothing><ENTER> (a quit symbol when used on
the first line) .. aborting ...\n";
exit;
}else{
push @input,$_;
}
}
for(@input){
print OUTFILE $_;
}
close(OUTFILE);
print "Here is what you've written\n\n";
sleep 1;
open(FILE,"<$outfile")or die "Can't open $outfile : $!";
while(<FILE>){
print;
}
close(FILE);
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/