Документация
HTML CSS PHP PERL другое

Workshop

 
Previous Table of Contents Next

Workshop

Quiz

1:

Variables are interpolated inside qq quotes.

  1. True

  2. False

2:

What value is stored in $c after running the following code?


$a=6;

$a++;

$b=$a;

$b--;

$c=$b;


  1. 6

  2. 7

  3. 8

3:

Concatenation can be performed only with the concatenation operator (.).

  1. True

  2. False

Answers

A1:

a. True. qq behaves in every way like a pair of double quotation marks. This means it can interpolate variables.

A2:

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.

A3:

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.

    Previous Table of Contents Next
    © 2000- NIV