Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.
#!/usr/bin/perl
#match5.pl

open(INFILE,"test2.txt") || die "$!";
print "Enter the pattern you wish to match: ";
chomp(my$pat=<STDIN>);
my$num_letters=0;
while(<INFILE>)
{
 if(/$pat/)
 {
  $pat=~/\w/gc;
  $num_letters++;
  print "$_ contains the pattern $pat and teh number of $pat is $num_letters\n";
 }
}
print "Number of $pat is $num_letters\n";
close(iNFILE);
share|improve this question
1  
This isn't really Ubuntu specific, you might wanna post it at stackoverflow.com –  htorque Nov 10 '10 at 14:10
add comment

1 Answer

There is no better answer for this particular question than that provided by the perl documentation.

So to answer your question, I'll show how to show this documentation, and find the relevant bit.

To install the perl documentation. (perldoc is a bit like man, in fact you can often call man on many of the perl documentation)

sudo apt-get install perldoc

To read a document, enter perldoc and then the document name.

perldoc perldoc #this is the perldoc about how to use perldoc
perldoc perl #this is a good starting point, tells you about some available documentation

But to fast forward and answer your question, you'll need to read

perldoc perlretut

and search for the section titled "Global matching"

hope that helps.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.