Workshop
Quiz
1. Variables are interpolated inside qq quotes.
True
False
What value is stored in $c after running the following code?
6
7
8
- Concatenation can be performed only with the concatenation operator (.).
True
False
$a=6; $a++; $b=$a; $b--; $c=$b;
Answers
-
a. True. qq behaves in every way like a pair of double quotation marks. This means it can interpolate variables.
-
a. $a is set to 6. $a is then incremented to 7, and assigned to $b. $b is decremented to 6, and assigned to $c.
-
b. False. A motto in the Perl community is "There Is More Than One Way To Do It" (TIMTOWTDI). Concatenation can be performed by including two (or more) scalars in a double-quoted string, as follows:
qq($a$b$c);
Activities
Write a short program that prompts the user for a Fahrenheit temperature and prints the temperature in Celsius. Converting Fahrenheit temperature to Celsius can be accomplished by taking the Fahrenheit temperature and subtracting 32, and then multiplying by 5/9. For example, 75 degrees Fahrenheit is 23.8 degrees Celsius.
Modify the Interest program in Listing 2.3 to print the amount with no more than two decimal places. You can do so without printf with clever use of the int operator, multiplication, and division.