Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
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: