INF3110/4110 Problems week 36 (30.8-3.9.2004) (The problem text is in English as we have foreign students who speak littel Norwegian.) Problem 1 Extend the i "Hello program" presented in the lecture to give your name: Hello, Xxx Xxx. Hint: The following Perl sentence will assign your name to the $Name variable: $Name = (getpwuid($<))[6]; Problem 2 Extend the problem even further to say "Good morning" or "Good evening" depending on the time of day. More specifically, the program should say "Good morning" between 6:00 and 12:00 "Good afternoon" between 12:00 and 18:00 "Good evening" between 18:00 and 22:00 "Good night" any other time. Hint: The Perl sentence ($Sec, $Min, $Hour) = localtime(time); will find the current time of day. Problem 3 Extend the program even further to print the time of day, like this: Good evening, Xxx Xxx. The time is now 21:16:01. Note that the minutes abd seconds should always be two digits, so an extra "0" must be inserted when either of the two is less than 10. Problem 4 We can compute the absolute value of $A by writing if ($A < 0) { $A = -$A; } (The absolute value of a number is always positive. The absolute value of 5 is 5, and the absolute value of -5 is also 5.) Write at least 4 other Perl statements that also compute the absolute value of a number. Problem 5 Write e Perl program which will print the following table: n n? n? 1 1 1 2 4 8 3 9 27 4 16 64 5 25 125 6 36 216 7 49 343 8 64 512 9 81 729 10 100 1000 Hint: The expression length($x) tells how many characters there are in $x. Problem 6 The Perl loop while (<>) { ... } will loop through all lines in the files specifies as parameters; the lines will successively be placed in $_. For example, the following loop will count the number of lines in the files: while (<>) { ++$N_lines; } Write a simplified version of the standard Unix program "wc" which counts the number of lines and the number of bytes in the specidied files. Problem 7 Solve problem 6 in another language you are familiar with, like C or Java. How long did it take to write each program?