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);
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Help with split() function
by driver8 (Scribe) on Mar 19, 2008 at 18:03 UTC |
In Section
Seekers of Perl Wisdom