HTML CSS PHP PERL

Workshop

 
Previous Table of Contents Next

Workshop

Quiz

1:

What does $ref contain after the statement $ref=\"peanuts";?

  1. Nothing. That syntax isn't valid.

  2. peanuts

  3. A reference to an anonymous scalar.

2:

What does this structure create?


$a=[

    { name=> "Rose", kids=> [ qw( Ted Bobby John ) ] },

    { name=> "Marge", kids=>[ qw( Maggie Lisa Bart ) ] },

];


  1. A hash of hashes, which contains a list

  2. A list of hashes, which contains a list

  3. A list of lists, which contains another list

Answers

A1:

c. A reference can be taken to any value, not just scalar, array, and hash variables. You can take references to a number also with $ref=\100;. If you answered a, it's a good idea to try new things with a short program or in the debugger to see what they do if you're unsure.

A2:

b. This structure wasn't covered explicitly in this hour, but you should have been able to guessthe answer. A list (the outer brackets) of hashes (the braces) contains a list (the data for kids).

Activities

  • Modify the Maze game to take diagonal direction as well. You might want to use four new keys to indicate those directions (ne, nw, se, and sw would be difficult to program). Hint: The secret is modifying @maze to use the new symbols and %direction to indicate which way they should go[1,1], [-1,-1], and so on.

  • Design a structureeven if just on paperto describe a phone bill. The bill itself contains keys and data like a hash (name, phone, address), and some parts of the bill are lists (itemized calls). Each itemized call could also be considered a hash (destination, time).

    Previous Table of Contents Next
    © 2000- NIV