Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: pre-texted <STDIN> with Term::ReadLine -- oneliner

by Discipulus (Canon)
on Apr 04, 2020 at 11:48 UTC ( [id://11115036]=note: print w/replies, xml ) Need Help??


in reply to pre-texted <STDIN>

hello ShainEdge and welcome to the monastery and to the wonderful world of Perl!

you can play with Term::ReadLine to accomplish your task. The following oneliner is a windows version and you have to force the underlaying readline module setting PERL_RL ENV var and also TERM one to be empty (not DUMB as cmd.exe IS DUMB ;)

perl -MTerm::ReadLine -E "BEGIN{$ENV{PERL_RL}='Perl';$ENV{TERM}=''} $ +term = Term::ReadLine->new(); $txt='spaghetti,pomodoro,vino'; $txt=$t +erm->readline('edit:',$txt); say 'new:',$txt" edit:spaghetti,pomodoro,vino # you now edit the line erasing 'pomodor +o' and hit RETURN new:spaghetti, vino

To adapt to Linux use single quotes around the oneliiner and double quotes inside it; you can probably remove the BEGIN block too.

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^2: pre-texted <STDIN> with Term::ReadLine -- oneliner
by ShainEdge (Novice) on Apr 04, 2020 at 13:24 UTC

    Ah! Thank you very much! I re-wrote it similar as a perl script, and it does what I was looking for it to do!

    I'm getting some non-critical errors in the script being run from the command line, based on it not being able to deal with the terminal size, but I should be able to get that sorted, if just dump the error messages to nul-space.

    "Unable to get Terminal Size. The Win32 GetConsoleScreenBufferInfo call didn't work. The COLUMNS and LINES environment variables didn't work. at C:/Strawberry/perl/vendor/lib/Term/ReadLine/readline.pm line 410.", in a Windows setting

    There is a great bunch of individuals here!

Re^2: pre-texted <STDIN> with Term::ReadLine -- oneliner
by ShainEdge (Novice) on Apr 04, 2020 at 13:03 UTC

    Thank you for the greeting. This looks, so-far as I have read your script, what I was shooting for.

    I went to read the "Term::Readline" documentation, and I would not have guessed it was able to do as you have presented, reading that document. That is what I had mentioned in an earlier statment. If I were to just search for this, I could take days of looking at hints that it could do what I wanted, based on the name, but come away, after reading it, not knowing it was the proper package/function.

      > If I were to just search for this, I could take days of looking at hints that it could do what I wanted

      indeed! there is CPAN search but.. for all the remaining part there is perlmonks! ;)

      Nothing like the experience from other users (not speaking about me), infact the perl community is one its best plus.

      You can also find IO::Prompt an interesting solution (dunno atm if it can prefill input but you can adapt my example to it)

      L*

      PS changed the title for personal indexing matters

      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11115036]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-03-28 16:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found