[SOLVED] [PERL] extract word from text file

Status
Not open for further replies.

maulin sheth

Advanced Member level 2
Joined
Oct 24, 2010
Messages
502
Helped
90
Reputation
179
Reaction score
90
Trophy points
1,318
Location
Bangalore, India
Activity points
4,161
Hello all,
I am new to perl.I want to know that how any word is extracted from the text file which have more number of lines.
Pl provide me some good materials for the perl.

Thanks & Regadrs,
 

Hello maulin,

As u r new to perl u can start with this code.. which will be easier...

To find the total number of words u can use this code....

$wordcount=0;
$line=<stdin>;
while($line ne "")
{
chop($line);
@arr=(split(/ +/, $line));
$wordcount+=@arr;
$line=<stdin>;
}
print("\nThe total number of words: $wordcount");


copy this code and paste in a file "filename.pl"

Then run using command

perl filename.pl


Enter a line which u need
press enter
Then press Ctr+d.

u can edit this based on file concept...


2..To match pattern


$line=<stdin>;
chop($line);
@arr=(split(/ +/, $line));
for($i=0; $i<@arr; $i++) {
if($arr[$i] =~ /mauli/ ) {
print $arr[$i]
}
}

:lol:
 

better download Learning PERL in 21 days book from net. Title : "Teach Yourself Perl in 21 Days". very useful
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…