#!/usr/bin/perl -W use strict; use 5.010; use Data::Dumper; my $heading = < "BigApple"); my %types = (tom => "admin"); my $menu = <; $input =~ s/^\s*//; #remove leading whitespace $input =~ s/\s*$//; #remove trailing whitespace return $input; } sub createAccount { print "Creating Account...\n"; my $userID = prompt4input ("Enter your userID: "); my $password = prompt4input ("Enter your password: "); if (exists $passwords{$userID}) { print "Error: Duplicate user id: $userID "; return; #### update added } my $account_type; while ($account_type = prompt4input( "Enter the account type, admin (or regular): "), $account_type !~ /admin|regular/) { $passwords{$userID} = $password; $types{$userID} = $account_type; } print "Account for \'$userID\' was successfully created \n"; } sub deleteAccount { my $userID = prompt4input ("Enter your userID: "); my $password = prompt4input ("Enter your password: "); if ($passwords{$userID} != "$password") { print "invalid user id/password combination!\n"; return; } if ($types{$userID} != "admin") { print "$userID is not an admin...can not delete!\n"; return; } delete $passwords{$userID}; delete $types{$userID}; } sub changePassword { my $userID = prompt4input ("Enter your userID: "); my $password = prompt4input ("Enter your password: "); if ($passwords{$userID} != "$password") { print "invalid user id/password combination!\n"; return; } my $newPassword = prompt4input ("Enter new password: "); $passwords{$userID} = $newPassword; } sub listUsers { # sort the users in descending order my $counter = 1; for my $userID (reverse sort keys %passwords) { print "$userID\t"; print "\n" if $counter++ % 3 == 0; #divisible by 3 evenly } print "\n"; }