in reply to How can I read and print lines that has only one word from a file
So you want to open a file and print out all lines that only contain one word? If so, this should work:
open FILE, "file.txt" or die $!; while (<FILE>) { chomp; print "$_\n" if $_ =~ /^(\w+)$/; } close FILE;
Let me know if you have any questions.
Update: ++'s to tadman for the improvements below.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: How can I read and print lines that has only one word from a file
by tadman (Prior) on Jul 15, 2002 at 04:17 UTC | |
Re: Re: How can I read and print lines that has only one word from a file
by Anonymous Monk on Jul 15, 2002 at 04:30 UTC | |
by tadman (Prior) on Jul 15, 2002 at 04:43 UTC |
In Section
Seekers of Perl Wisdom