Jonathan Dwerryhouse wrote:
Hi,

Could someone point me in the right direction?

I'd like to write a programme in Perl that will prompt questions and dump the answers into a templated piece of text. E.g:

User            jonathan
Password    shampoo
Call ID         8007835373

Each time i only want to change the user and password but inject it back into this basic template.

Also, is there a way for the script to prompt for the questions and with the provided answers, append the file?


I am somewhat confused on what you are attempting to do, you use the words "inject" "append" and "dump", so we need to figure out a little more clearly what you are after.


Are you trying to change the values of the file as they currently are in place? Or are you trying to add the values combined with the template onto the end of a list? Or are you trying to create a new file similar to the template based on the format of the template with the new values added?

In any of the cases you are probably going to need the read, write and maybe append modes of 'open'. So you may want to start here:

perldoc perlopentut
perldoc -f open

As for your first question there are tons of ways to do that, Something simple like the following:

- UNTESTED -

my $value = '';
while ($value eq '') {
  print "Please enter 'y' or 'n':\n";

  my $input = <STDIN>;
  chomp $input;

  # test for valid input, for example a yes or no answer
  if (($input =~ /^y/i) || ($input =~ /^n/i)) {
      $value = $input;
  }
  else {
      print "Invalid entry: $input. Try again.\n";
  }
}

Or you can get as complex as needed, using modules from CPAN that handle terminal input, or CLI creation, etc.

http://danconia.org


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to