I would use
Term::Interact like so
#!/usr/bin/perl --
use strict;
use warnings;
use Data::Dumper;
use Term::Interact;
print Dumper( prompt_customer() );
sub prompt_customer {
my %customer;
my $ti = Term::Interact->new;
$customer{firstname} = $ti->get(
msg => "\nComputer Information\n-----------------------\n",
prompt => "Customer First Name: ",
check => [ qr/^\w+$/, ],
);
$customer{lastname} = $ti->get(
msg => "",
prompt => "Customer Last Name: ",
check => [ qr/^\w+$/, ],
);
$customer{phone} = $ti->get(
msg => "",
prompt => "Customer Phone #: ",
check => [ qr/^[\d\s\-\,]+$/, ],
);
$customer{email} = $ti->get(
msg => "",
prompt => "Customer Email: ",
check => [ qr/^\S+$/, ],
);
$customer{compman} = $ti->get(
msg => "\nComputer Information\n-----------------------\n",
prompt => "Computer Manufacturer: ",
);
$customer{compmodel} = $ti->get(
msg => "",
prompt => "Computer Model: ",
);
$customer{compModelNum} = $ti->get(
msg => "",
prompt => "Computer Model #: ",
);
$customer{errormsg} = $ti->get(
msg => "",
prompt => "Error Message (if any): ",
);
$customer{os} = $ti->get(
msg => "",
prompt => "Operating System: ",
);
$customer{probdesc} = $ti->get(
msg => "",
prompt => "Problem Description: ",
);
$customer{loginpw} = $ti->get(
ReadMode => 2,
msg => "",
prompt => "Administrator/Root Login Password: ",
);
$customer{service} = $ti->get(
msg => "",
prompt => "Computer Service Needed: ",
);
$customer{barcode} = $ti->get(
msg => "",
prompt => "Barcode Number: ",
);
$customer{date} = scalar localtime;
print "\n";
return \%customer;
}
__END__
### for testing, COPY/PASTE when prompted
first
last
444 444 444
asdf@email.com
manu
mode
33
err
os
prob
rootpass
compserv
barcode
## sample session
Computer Information
-----------------------
Customer First Name: first
Customer Last Name: last
Customer Phone #: 444 444 444
Customer Email: asdf@email.com
Computer Information
-----------------------
Computer Manufacturer: manu
Computer Model: mode
Computer Model #: 33
Error Message (if any): err
Operating System: os
Problem Description: prob
Administrator/Root Login Password:
Computer Service Needed: compserv
Barcode Number: barcode
$VAR1 = {
'probdesc' => 'prob',
'firstname' => 'first',
'date' => 'Tue Sep 22 12:44:24 2009',
'barcode' => 'barcode',
'lastname' => 'last',
'service' => 'compserv',
'phone' => '444 444 444',
'os' => 'os',
'email' => 'asdf@email.com',
'loginpw' => 'rootpass',
'errormsg' => 'err',
'compModelNum' => '33',
'compman' => 'manu',
'compmodel' => 'mode'
};
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.