negzero7 has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Help with split() function
by GrandFather (Saint) on Mar 19, 2008 at 01:58 UTC | |
Re: Help with split() function
by driver8 (Scribe) on Mar 19, 2008 at 01:03 UTC | |
by negzero7 (Sexton) on Mar 19, 2008 at 01:17 UTC | |
by driver8 (Scribe) on Mar 19, 2008 at 01:39 UTC | |
by negzero7 (Sexton) on Mar 19, 2008 at 01:57 UTC | |
by dragonchild (Archbishop) on Mar 19, 2008 at 02:06 UTC | |
by negzero7 (Sexton) on Mar 19, 2008 at 01:36 UTC | |
by cdarke (Prior) on Mar 19, 2008 at 02:02 UTC | |
by halfcountplus (Hermit) on Mar 19, 2008 at 02:16 UTC | |
Re: Help with split() function
by toolic (Bishop) on Mar 19, 2008 at 02:01 UTC | |
Re: Help with split() function
by wrinkles (Pilgrim) on Mar 19, 2008 at 10:18 UTC | |
by driver8 (Scribe) on Mar 19, 2008 at 18:03 UTC | |
Re: Help with split() function
by hipowls (Curate) on Mar 19, 2008 at 10:19 UTC | |
Re: Help with split() function
by carol (Beadle) on May 29, 2008 at 22:41 UTC |
Back to
Seekers of Perl Wisdom