Previous Page Next Page

7.4. What's Next?

In the next chapter, you will learn about pattern matching with regular expressions, one of the best and most important features of the language. You will learn about expression modifiers and how to find patterns in text strings. If you are familiar with the UNIX grep or the vi editor, you will see how Perl enhances and simplifies the power of pattern matching with its matching and substitution operators and large selection of regular expression metacharacters.

Exercise 7: What Are Your Conditions?

1.Physicists tell us that the lowest possible temperature is absolute zero. Absolute zero is –459.69 degrees Fahrenheit.
  1. Accept inputs from the user: a beginning temperature, an ending temperature, and an increment value (all Fahrenheit).

  2. Check for bad input: a temperature less than absolute zero and an ending temperature less than a beginning temperature. The program will send a message to STDERR if either condition is detected.

  3. Print a header showing: "Fahrenheit Celcius". Print all the values from the beginning to the ending temperatures. Use a looping mechanism. The conversion formula is: C = (F – 32) / 1.8

2.Ask the user for a list of grades, separated by whitespace. The grades will be stored in a string called $input.
  1. Split the string $input and create an array.

  2. Use the foreach loop to get the total sum of all the grades.

  3. Print the average.

3.Write a script that will print 10 random number cards from a deck.
  1. The script will build a deck of 52 cards by using nested foreach loops.

  2. The outer loop will iterate through a list consisting of cards for each suit: clubs, diamonds, hearts, spades. The inner loop will iterate through a list for each type of card within the suit: ace, 1 through 10, jack, queen, and king. A card of each suit will be assigned to an array

  3. The rand() function will be used to get a random card from the pack. There should be no duplicates in the 10 cards selected from the deck.


 

Previous Page Next Page