Q&A

Q1:The pattern /\W(\w)+\W/ doesn't seem to match all the words on the line, just the ones in the middle. Why?
A1: You're looking for word characters surrounded by nonword characters. The first word of the line—assuming it starts at the beginning of the line—doesn't have a nonword character in front of it. It doesn't have a character in front of it at all.
Q2:What's the difference between m// and //? I don't get it.
A2: There's almost no difference at all. The only difference is that if you decide to specify a pattern delimiter other than /, you can do so only if you precede the pattern with an m—for example, m!pattern!.
Q3:I'm trying to verify that the user typed a number, but /\d*/ doesn't seem to work. It always returns true!
A3: It returns ...

Get SAMS Teach Yourself Perl in 24 Hours THIRD EDITION now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.