Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top