my @array; @array = <FILE>; # slurp whole file
Then is easy to get what you want:
my @lines_with_single_word = grep /^\s*\S+\s*$/,array; # ^\s*\S+\s*$ means beginning of line, 0 or more whitespace, 1 or more non-whitespace (the word), 0 or more ws and the end of line
Naser Ali wrote:
Hello,
I have an array which was created by slurrping a whole text file. There are certain element in the array after reading the files which contain only one word. I want to only match those array elements which contain a single word and print it. Tried every thing but in vain. I must be doing something wrong, can any one please suggest the right way of doing this.
Thanks
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>