Hi, I am trying to get this script to find words with the letter 'P' in it (case insensitive so p or P) and then print out each word it finds in the file. I'm reading in from a text document.
I thought using the split function would be the best way to go. Here's my code so far:
#!usr/bin/env perl use warnings; use strict; open my $test_fh, '<', @ARGV or die "Can not open file $!\n"; while (<$test_fh>) { my @line = split (); # if ($line[1] =~ /\wP\w/i); print "$line[1]"; } close ($test_fh);
The text I'm testing it with is this:
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 only prints out standsandisis'H' . Can someone point out my errors and what I should be doing?
In reply to Help with split() function by negzero7
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |