#! /lusr/bin/perl -w

use feature qw(switch say);

$num = @ARGV;
if ($num < 1) {
    die "Usage: ./l14.pl testnumber\n";
}

# Success story!
# gawk 'NF == 6 { $3 = $3/2.0 } { print }' ~edwardsj/cs108/files/traces.linec

given ($ARGV[0]) {
    when(1) {
	# What is printed?
	# A) Yup
	# B) nothing
	# C) none of the above
	if ("Linux" =~ /inu/) {
	    print "Yup\n";
	}
    }
    when(2) {
	# What is printed?
	# A) Yup
	# B) nothing
	# C) none of the above
	if ("Linux" =~ /linu/) {
	    print "Yup\n";
	}
	# How can we fix this?
    }
    when(3) {
	# What is printed?
	# A) Yup
	# B) nothing
	# C) none of the above
	if ("Linux" =~ /Linuxa*/) {
	    print "Yup\n";
	}
    }
    when(4) {
	# What is printed?
	# A) Yup
	# B) nothing
	# C) none of the above
	print "Yup\n" if "Linux" =~ /Linuxa*/;
    }
    when(5) {
	# What is printed?
	# A) Yup
	# B) nothing
	# C) none of the above
	print "Yup\n" if "Linux" !~ /Linux/;
    }
    when(6) {
	# What is printed?
	# A) Yup
	# B) nothing
	# C) none of the above
	$re = qr/inu/;
	print "Yup\n" if "Linux" =~ $re;
    }
    when(7) {
	# What is printed?
	# A) They were the best of times
	# B) They were the worst of times
	# C) $tale\n
	# D) none of the above
	$tale = "They were the best of times";
	$tale =~ s/best/worst/;
	print "$tale\n";
    }
    when(8) {
	# What is printed?
	# A) 1 {2} 3 {4} 5
	# B) 1 2 3 4 5
	# C) 1 3 5
	# D) none of the above
	$string = "1 {2} 3 {4} 5";
	$string =~ s/{.*} //;
	print "$string\n";
    }
    when(9) {
	# What is printed?
	# A) 1 {2} 3 {4} 5
	# B) 1 2 3 4 5
	# C) 1 3 5
	# D) none of the above
	$string = "1 {2} 3 {4} 5";
	$string =~ s/{[^}]*} //;
	print "$string\n";
    }
    when(10) {
	open (my $infile, "/u/edwardsj/cs108/files/employees.txt") or die "Failed to open\n";
	while ($line = <$infile>) {
	    print $line;
	}
    }
    when(11) {
	open (my $infile, "/u/edwardsj/cs108/files/employees.txt") or die "Failed to open\n";
	while ($line = <$infile>) {
	    $line =~ s/\$//g;
	    print $line;
	}
    }
    when(12) {
	open (my $infile, "/u/edwardsj/cs108/files/employees.txt") or die "Failed to open\n";
	while ($line = <$infile>) {
	    $line =~ s/[\$,]//g;
	    print $line;
	}
    }
    when(13) {
	open (my $infile, "/u/edwardsj/cs108/files/employees.txt") or die "Failed to open\n";
	while ($line = <$infile>) {
	    $line =~ s/[\$,]//g;
	    @fields = split(/\s+/, $line);
	    say $fields[4];
	}
    }
    when(14) {
	open (my $infile, "/u/edwardsj/cs108/files/employees.txt") or die "Failed to open\n";
	while ($line = <$infile>) {
	    @fields = split(/\s+/, $line);
	    $amount = $fields[4];
	    $amount =~ s/[\$,]//g;
	    if ($amount > 6000) {
		print $line;
	    }
	}
    }
    when(15) {
	open (my $infile, "/u/edwardsj/cs108/files/traces.linec") or die "Failed to open\n";
	while ($line = <$infile>) {
	    @fields = split(/\s+/, $line);
	    $numfields = @fields;
	    if ($numfields == 6) {
		$fields[2] /= 2;
	    }
	    # How can we fix this output?
	    say @fields
	}
    }
    when(0) {
	# 
	# A) 
	# B) 
	# C) 
	# D) 
    }
}
