in reply to Re: Help with split() function
in thread Help with split() function

Looks pretty good, but I'll make some suggestions. Instead of "[^\w]" you can use "\W". It means the same thing. Also putting "if (@pmatch)" before your "foreach" is redundant. If there is nothing in the array, it won't enter the loop. Here's my solution:

while (<DATA>) { for (split /\W/) { print "$_\n" if /p/i; } } __DATA__ CPAN stands for comprehensive Perl Archive Network. ^ and $ are used as anchors in a regular expression. /pattern/ is a pattern match operator. Perl is very easy to learn. Enter 'H' or 'h' for help.

It separates punctuation and other "\W" characters in the split statement. Then it skips any temporary arrays and just prints if the element contains a "p".


-driver8