dakenah johnson wrote:

Hi,
I am trying to write a script that reads names fron standard input and matches it to a key in a given table and prints out the name and key


Enter a first name or " <ctrl -z>", to exit
chomp { $name = <STDIN> };
while $name ne " <ctrl-z>"
if $name is in @given_table
then
print "$name maps to $value in given_table"
else
print "$name is not in the given_table\n"

what is wrong with this script?
Well your while should be on the STDIN rather than on the $name.

Ctrl+z is generally caught by the controlling shell to suspend the process, so your script is likely never going to receive that particular entry.

while (<STDIN>) {
chomp;
if (grep $name, @given_table) {
print "$name maps to ...";
}
}

Is closer to what you want, in general the process can be killed by the shell by issuing a ctrl+c so you really shouldn't need to catch the signal, just instruct the user what to do and let the shell handle it.

http://danconia.org


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



Reply via email to