| Previous | Table of Contents | Next |
Difficulty: Medium
Consider the array (2, 7, 4). Without explicitly accessing individual array elements with brackets or splice() or shift() or pop(), find one simple Perl expression that extracts the 2, one that extracts the 4, and one that yields 3, the number of elements in the array.
Humphrey: I understand loops a lot better now. But Im not sure what to make of these contexts and default variables.
Ingrid: Me neither. Ive never seen anything like them in any programming language.
Humphrey: They seem dangerous. Programming languages shouldnt be like real languages. They should enforce a uniform style and syntax so theres only one way to solve a problem. That way, its easy to understand programs other people write.
Ingrid: You wont like Perl, then, since it gives you several ways to do just about everything.
Modify tickets5 so it asks users to name movies. If a user types the name of a movie that isnt in @movies, your new program should append it.
Hint: Use foreach, eq, and push().
Modify tickets3 so it prompts the user to name several movies and then prints them in reverse order.
Hint: Use a for loop. (Dont use the reverse() function from Chapter 4, Session 6. Thats cheating.)
Modify tickets5 so it accepts a rating from the command line and then prints all the movies that have a lower rating.
Write a program that does the following:
Make sure that any input is OK; your program should truncate any decimals and reprompt the user if the input is too small or too large.
Hint: Use the x operator and two for loops, one nested inside the other.
| Previous | Table of Contents | Next |