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 1
Joined
Oct 24, 2010
Messages
497
Helped
90
Reputation
179
Reaction score
88
Trophy points
1,318
Location
Bangalore, India
Activity points
4,130
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,
 

vijayR15

Full Member level 3
Joined
Dec 10, 2011
Messages
173
Helped
69
Reputation
136
Reaction score
63
Trophy points
1,308
Activity points
2,381
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:
 

sakthikumaran87

Full Member level 3
Joined
Nov 9, 2009
Messages
160
Helped
21
Reputation
42
Reaction score
21
Trophy points
1,298
Location
India
Activity points
2,176
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

Top