#!/usr/bin/perl -w
# lab #8 solution
#----------------------------------------------------------------------


# 1. Prompt the user to enter the month and day of week. Print each to the 
#    terminal as a capitalized three letter abbreviation (e.g. August == Aug).
print "Please enter the current month: ";
chomp($mon = <STDIN>);
print "The abbreviation for $mon is ".ucfirst(lc(substr($mon, 0, 3)))."\n";

print "Please enter the current day of the week: ";
chomp($wday = <STDIN>);
print "The abbreviation for $wday is ".ucfirst(lc(substr($wday, 0, 3)))."\n";

# 2. Prompt the user to enter their full name.
print "Enter your full name: ";
chomp($ans = <STDIN>);
($first, $last) = split(/\s+/, $ans);

# 4. Print this returned username value to the screen.
$user_name = &UserName($first, $last);
print "Username for $ans is $user_name\n";

# 5. Print the returned username value in all upper case to the screen.
print "Uppercase $user_name is ".uc($user_name)."\n";

# 6. Print the returned username value in all lower case to the screen.
print "Lowercase $user_name is ".lc($user_name)."\n";

# 7. Print the returned username value to the screen with the first and last 
#    characters lower case and all of the middle characters all upper case.
$weirdcase = lc(substr($user_name, 0, 1)).
    uc(substr($user_name, 1, (length($user_name) - 2))).
    lc(substr($user_name, (length($user_name) - 1), 1));
print "Weird cased $user_name $weirdcase\n";

# 8. If the first three characters of the username contain a letter "e" print 
#    some information about its status to the screen.
if(substr($user_name, 0, 3) =~ /e/) {
    print "The first three characters of $user_name contain an e.\n";
}else{
    print "There is no letter e in the first three characters or $user_name.\n";
}

# 9. Prompt the user to enter at least five words.
print "Enter a series of at least five words. ";
chomp($words = <STDIN>);

# 9a. Split the entered string up so that each word is an item in an array.
@allwords = split(/\s+/, $words);

# 9b. Join the elements of the array with the "|" character into a single 
#     lower-case string and print to the terminal.
$pipejoined = join('|', @allwords);
print "The words joined with the '|' character: $pipejoined\n";


foreach $k (@allwords) {
    # 9c. Capitalize each element in the array and print to the screen
    print "Capitalized $k: ".ucfirst(lc($k))."\n";
    # 9d. Print to the terminal in all upper-case any word that at least five 
    #     characters long
    if(length($k) >= 5) {
        print uc($k)." is five or more characters in length.\n";
    }
}

exit;

# 3. Create a subroutine that accepts first and last name as arguments and 
#    returns a lower case string comprised of the entere last name and first 
#    initial as a single word (ie. "Mark Tucker" would be returned as "tuckerm") #    when passed the first and last name as arguments.
sub UserName {
    my $fname = $_[0];
    my $lname = $_[1];
    my $username = lc($lname).lc(substr($fname, 0, 1));
    return($username);
}