Perl Exercises 4 ---------------- These exercises use eval. 1. pcalc.pl given below is a Perl calculator. It accepts any Perl expression and evaluates it. It is very powerful. However, it is very dangerous as it will accept 'system("rm -rf ~)' that will wipe out the user's entire home directory. Modify pcalc.pl to make it safe. It should only accept arithmetic and logical expressions. Hint: use regexp for validation of the input. while (<>) { print eval; print "\n"; } 2. Write a simple trignometric calculator, tcalc.pl. It should accept any trignometric function, such as sin, cos, tan, etc, and an argument, and print the result of applying the function to the argument. Before execution, verify that the function is in the list of trig functions. Catch errors and print suitable messages. Hint: hash tables may be useful. 3. The function FileCountLines(inf) accepts a filename, opens the file and counts the number of lines in the file. Complete the body of the function. Write Perl code that accepts a filename from the user, calls FileCountLines() and prints the resulting line count. In case the file cannot be opened, it prompts the user for another filename. sub FileCountLines() { my ($fname) = @_; # argument filename open (INF, $fname) || die "Could not open $fname"; <<< insert code here to count the number of lines >>> return $linecount; } * * * * *