plain-text file parsing

R

Russell Klopfer

Hello. I would like to know how I can parse a plain-text file. All I
want to do is be able to sequentially extract each word from a
document. Similar to the StringTokenizer in Java. Is there a module
for this? or an easy way to do it with regular expressions?

Thanks!
 
R

Roger Nordqvist

Russell said:
Hello. I would like to know how I can parse a plain-text file. All I
want to do is be able to sequentially extract each word from a
document. Similar to the StringTokenizer in Java. Is there a module
for this? or an easy way to do it with regular expressions?

Thanks!

Dont really know what you want to do with the textfile.

A usual way to work with file:

open FILE, "/home/barry/text.txt" or
die "Cant open file";

while( $line = <FILE>)
{
... do something with $line ...
}

close FILE;


This parses the textfile line by line

/Roger
 
J

Jürgen Exner

Roger said:
Dont really know what you want to do with the textfile.
A usual way to work with file:

open FILE, "/home/barry/text.txt" or
die "Cant open file";
while( $line = <FILE>)
{
... do something with $line ...
}
close FILE;

Actually the idiomatic Perl way would be
while(<FILE>) {
... do something with $_ ...
}

jue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top