in reply to
Help with split() function
I'm working through some of these "Seekers" questions as a learning tool. This is my first perlmonks post. :)To print one "word" per line, stripping out punctuation at the end, try this:
#!/usr/bin/perl
use warnings;
use strict;
my $filename = shift;
open my $TEST_FH, '<', "$filename" or die "Cannot open file $filename
+\n$!\n";
while (<$TEST_FH>) {
chomp;
my @words = split;
my @pmatch = grep {/p/i} @words;
if (@pmatch) {
foreach (@pmatch) {
s/[^\w]$//;
print "$_\n";
}
}
}
close ($TEST_FH);