Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

II. Answers > N. Answers to Chapter 14 Exercises

Appendix N. Answers to Chapter 14 Exercises

Answer 14.1: Start the program by printing a short message reminding you to enter some lines of input. If you don’t give the program any command-line arguments, the line input operator <> will wait for standard input, so you don’t stare at the terminal waiting for something to happen as your program is staring at you waiting for you to type.

Use index on each line to look for the string “perl”. If the line doesn’t have it, index returns -1 (0 means it was the first character). Assign the value to $pos then check if its value was not -1, meaning you found “perl”. If you found “perl”, output a message that shows its position. If index returned -1, simply output a string that says you didn’t find it:


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint