[wellylug] Default value in read

Grant McLean grant at mclean.net.nz
Wed May 9 11:04:43 NZST 2007


On Wed, 2007-05-09 at 10:53 +1200, michael at diaspora.gen.nz wrote:
> > (In which I want the user to be able to be able to EDIT the default 
> > value, as most times the default is correct, or needing a minor change, 
> > e.g. ".com" might change to "co.nz" )
> 
> bash doesn't provide this (as other people have noted); nor does ksh, from
> a quick check.  zsh might, but then, most people don't have zsh installed.
> 
> dialog(1) on a Debian system could probably be used, as could (if you
> can assume graphicality & Gnome) zenity; but those all have portability
> drawbacks.
> 
> Ruby & PHP may have utilities that would be usable; IO::Prompt, the
> Perl module for this sort of thing, doesn't appear to support editable
> defaults.

I haven't used IO::Prompt, but Term::ReadLine does support that type of
functionality depending on what readline backends are installed.  For
example, with Term::ReadLine::Gnu, this code works:

  use Term::ReadLine;
  my $term = new Term::ReadLine;
  my $name = $term->readline('Country of residence: ', 'NZ');

Regards
Grant





More information about the wellylug mailing list