in reply to Using associative arrays with I/O to interact with Prog. User
update: corrected chop to chomp (thank-you toolic)#!/usr/local/bin/perl #Family.pl use strict; use warnings; my %family = ('Connie' =>'Mama', 'Brandy' =>'Sissy', 'Pete' =>'Dude', 'Tristan' =>'Stinky', 'Sophera' =>'Finky', 'Priscilla'=>'BearDawg'); print"Please type in your name: "; my $name = <STDIN>; chomp $name; # It's good to chomp # Convert to lower case with uc first char $name = ucfirst(lc $name); # Check for the absence of $name as a key if( !exists $family{$name}) { print"Thank you $name for participating but you are not family.\n" +; } else { print"Hey $family{$name}, thank you for being family!\n"; }
|
|---|