Updated Question: How do I search in Perl?

I need to search for words in a txt file (see below) that begin with "p" and "P" and words that end with "p" and "P" and print them out. Thank the people who have helped me answer my previous question.

Text File:
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.

#!/usr/local/bin/perl
open INPUT, "<proj2_part3.txt" or die "File not found\n";
while (<INPUT>)
{
my($line) = $_;
chomp($line);
if ($line =~ m\b\^p*\bi) {print "$&&#92;n";}
if ($line =~ m/p$*/i) {print "$&&#92;n";}
else {print "No match, sorry.\n";}
}
close INPUT;

The output is supposed to be:
Perl
pattern
pattern
Perl
help

But I only get:
P
p
p
P
p

How do I make the program print out the whole word?


Related Blogs

Perl script pauses twice – how do I make it continue without getting carriage returns from the keyboard?

This is a cross post from my question in Mahalo Answers and Google Perl Beginners Group.

I am using the executable cakecmd unzipper in a Perl script. Normally when cakcmd is executed outside of Perl and it’s done it’s work it pauses and one has to hit enter to return to the prompt.

How can I program Perl so that it enters the carriage return for me? Printing a carriage return doesn’t work, it just adds an additional line between prompts. At this point I call cakecmd twice, and so to complete my script I have to hit the Enter key twice within my Windows CMD console.

I got a promising response from Perl Beginners Google Group that suggest I use the CPAN Perl Module called Expect, however I am unclear how to use it. How can I tell Perl to use Expect, to look for a no time limit pause and then execute a carriage return?

Thanks
Thanks for the first answer. It doesn’t work using either the system or the exec function. The system function gives me errors, the exec works but still has the same pauses requiring carriage returns. The parameter < ^M, doesn’t seem to make a difference.


Related Blogs

Is Activeperl a comprehensive perl development environment?

I’d like to do some e-commerce development in perl, but am wondering
if Activeperl has all the necessary modules! Do I need to install additional CPAN modules on top of it? Thanks for your help.


Related Blogs

How can I install a specific version of perl module using CPAN? eg XML::SAX (0.14)?

If any provosion to specify perl module version in installation command?


Related Blogs

legitimate work from home jobs | Event Planning Bay Area | rent video games | Homeloans | Plumbing Courses in Manchester | increase fertility | Green Drink | Photo Keyring | Vitamin D Deficiency Symptoms | skip bags | Order Fulfillment Software | virtual receptionist | Educators Credit | bodybuilding workouts | window cleaning