Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Print names corresponding to numbers in a list
#################################################################################
# Script: nuum2name.pl
# Author: Jefferson Kirkland
# Company: JK Web Development
# Copyright: 2008
#
# Description: This script takes a list of numbers, supplied by the user, and
# converts the numbers into names. The script then prints them out to show the
# user what names the numbers corresponded to.
#
#################################################################################
use strict;
use warnings;
my %names = (1 => "Joe",
2 => "Bob",
3 => "George",
4 => "Connor",
);
print("Please enter your list of numbers from 1 to 4, one number per line. Press Ctrl-Z when finished.\n");
my @num = <STDIN>;
print("There are $#num elements in the array");
print("The names you requested are:\n");
foreach my $line (@num)
{
chomp($line);
#print("$line\n");
print("$names{$line}\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment