#!/usr/bin/perl use strict; $| = 1; # Prompt for input # ---------------- # Two arguments, prompt, and default value sub prompt($$) { my ($prompt, $default) = @_; my $x; $prompt .= ":" if $prompt =~ /.*[a-zA-Z]/; print "$prompt [$default] "; $x = ; chop($x); $x = $default unless $x; $x = "" if $x eq " "; return $x; } # Prompt for input block # ---------------------- # Two associative arrays as arguments: # list2{"key"} -> prompt string for that value # list3 -> array of keys in desired order # list1{"key"} -> current values # return a modified list1. sub promptBlock { my $prompts = shift; my $values = shift; my $keys = shift; my %results; my $widestPrompt; my $i; my $key; my $length; my $prompt; my @keys; if(!$keys) { @keys = keys(%$values); $keys = \@keys; } foreach $key (@$keys) { $length = length($$prompts{$key}); $widestPrompt = $length if $widestPrompt < $length; } foreach $key (@$keys) { $prompt = $$prompts{$key}; $prompt = $key if !$prompt; $length = length($prompt); while($length++ < $widestPrompt) { $prompt = " ".$prompt; } $$values{$key} = prompt($prompt,$$values{$key}); } } sub print_bar { print <