Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: <STDIN> "anticipate" input?

by tptass (Sexton)
on Aug 11, 2008 at 20:16 UTC ( #703743=note: print w/replies, xml ) Need Help??

in reply to <STDIN> "anticipate" input?

What you are trying to do of "anticipating the input" cannot be done, with the value being editable on the command-line. You can like the others have kindly suggested use a method to give a default value, like Term::UI, which could even give the user(s) a list of option to choose from.

Other than prompting the user on the command-line, the only way to accomplish what you are looking for is using Perl/Tk; where you would create a GUI display with the editable value.

Replies are listed 'Best First'.
Re^2: <STDIN> "anticipate" input?
by johnnyjohnny (Initiate) on Aug 11, 2008 at 20:31 UTC
    Yeah, that's kinda what I thought. Tryin' to use Perl/TK right now...

      You are probably way on your way with this, but I figure I would give you two examples in one. The first you will see is the Tk::FileSelect, which brings up a browser window for the user to select a file from (I prefer this solutions, simply because history has shown my not to trust the user). However, if what you are trying to do is a little more complex than you can simply implement this by using Tk::Entry, which is an easier solution than using a Textbox.

      #!/usr/bin/perl -w use Tk; use Tk::FileSelect; use strict; my $mw = MainWindow->new; #Solution #1 the next two lines! my $FSref = $mw->FileSelect(-directory=>"C:/"); my $dir = $FSref->Show; #solution #2 up until MainLoop $mw->Label(-text => 'File Name: ')->pack; my $filename = $mw->Entry(-width => 50, -textvariable => "$dir"); $filename->pack; $mw->Button( -text => 'Print', -command => sub{do_print($filename)} )->pack; MainLoop; #used by solution #2, to print the output to the terminal sub do_print { my ($file) = @_; my $file_val = $file->get; print "You selected $file_val\n"; }
Re^2: <STDIN> "anticipate" input?
by MidLifeXis (Monsignor) on Aug 12, 2008 at 14:55 UTC
    What you are trying to do of "anticipating the input" cannot be done, with the value being editable on the command-line.

    Very strong words, considering the shell does it all the time.

    There may not be a module to do this (and I am not fully convinced of this), but it most definitely can be done. At the very worst, you would need to push the prefill onto the line, and process the backspaces / ^H yourself.

    Update: See Term::ReadKey as a very possible tool to use to implement this, and Re: <STDIN> "anticipate" input? points to Term::ReadLine, which also looks like it could work (see addhistory as a possible method to do this).


Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2023-12-06 20:13 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (31 votes). Check out past polls.