/
config_creator.pl
59 lines (35 loc) · 1.02 KB
/
config_creator.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/perl
=head1 NAME
config_creator.pl - read a configuration description and prompt for value
=head1 SYNOPSIS
config_creator.pl description_file
=head1 DESCRIPTION
The config_creator.pl program reads a configuration description file
and then prompts the user for values, creating a configuration file
in the process.
=head1 SOURCE AVAILABILITY
The source is in Github:
http://github.com/briandfoy/configreader-simple/
=head1 AUTHORS
brian d foy, E<lt>briandfoy@pobox.comE<gt>
=head1 COPYRIGHT
Copyright © 2002-2024, brian d foy <briandfoy@pobox.com>. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
my $config = '';
while( <> ) {
next if m/\s*#/;
chomp;
my( $directive, $description ) = split m/\s+/, $_, 2;
my $answer = prompt( $description );
$config .= "$directive $answer\n";
}
print $config;
sub prompt maps {
my $message = shift;
print "$message> ";
my $answer = <STDIN>;
chomp $answer;
return $answer;
}