On Tue, Sep 22, 2009 at 23:10, Harry Putnam <rea...@newsguy.com> wrote:
> "Chas. Owens" <chas.ow...@gmail.com> 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..
snip

Term::Readline is more for writing programs with prompts (e.g. bash).
If you want to give the user a full editor, why not just drop them
into vi:

#!/usr/bin/perl

use strict;
use warnings;

use File::Temp qw/tempfile/;

#this is the safest way to get a temporary filename
my $tmpfile = do {
        my ($fh, $filename) = tempfile();
        close $fh;
        $filename;
};

my $editor = $ENV{EDITOR} || "/usr/bin/vi";

system($editor, $tmpfile) == 0
        or die "error occured while trying to run editor\n";

my $contents = do {
        local $/;
        open my $fh, "<", $tmpfile
                or die "could not open $tmpfile: $!\n";
        <$fh>;
};

unlink $tmpfile
        or die "could not delete <$tmpfile>: $!";

print "you wrote: [$contents]\n";


-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to