By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,876 Members | 1,239 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,876 IT Pros & Developers. It's quick & easy.

plain-text file parsing

P: n/a
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!
Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Russell Klopfer wrote:
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
Jul 19 '05 #2

P: n/a
Roger Nordqvist wrote:
Russell Klopfer wrote:
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?


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
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.