In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] writes:
>[EMAIL PROTECTED] (Peter Scott) writes:
>
>> In article <[EMAIL PROTECTED]>,
>>  [EMAIL PROTECTED] writes:
>>>Before starting to write my script designed to make filename changing
>>>easier I'd like to ask how to create an editable command line inside a
>>>perl script?
>> [snip]
>>
>> Term::ReadLine
>
>Ah yes.  Any idea how to make perl insert a string (actually a file
>name from an earlier process into that command line?
>
>Just inserting a sting to test like this doesn't work.  The sting
>isn't editable.

Right, it's not inserted, it's just in the prompt.

>From the perldoc example for Term::Readline
>
>use Term::ReadLine;
>my $term = new Term::ReadLine 'Simple Perl calc';
>my $prompt = "Enter your arithmetic expression: <SOMETHING HERE>";
>my $OUT = $term->OUT || \*STDOUT;
>while ( defined ($_ = $term->readline($prompt)) ) {
>   my $res = eval($_);
>   warn $@ if $@;
>   print $OUT $res, "\n" unless $@;
>   $term->addhistory($_) if /\S/;
>}
>
>How can I get an editable file name in there programatically?

You need a more capable ReadLine package.  Install
Term::ReadLine::Gnu and do:

BEGIN { $ENV{PERL_RL} = 'Gnu' }
use Term::ReadLine;
my $term = new Term::ReadLine 'Simple Perl calc';
my $prompt = "Enter your arithmetic expression: ";
my $OUT = $term->OUT || \*STDOUT;
while ( defined ($_ = $term->readline($prompt, '<SOMETHING HERE>')) ) {
   my $res = eval($_);
   warn $@ if $@;
   print $OUT $res, "\n" unless $@;
   $term->addhistory($_) if /\S/;
}

-- 
Peter Scott
http://www.perldebugged.com/
*** NEW *** http://www.perlmedic.com/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to