Naser Ali wrote:
It works,
What is it that works?
The data pattern looks like this;
Aword
Yep, that's one word.
<snip>
Aword Anotherword
That's two words. None of the posted suggestions matches that line.
You said in your original post:
"I want to only match those array elements which contain a single word
and print it."
I have to slurp the file first in an array in order to do some
clean up and parsing before I can get to this.
Why do you say that you *have* to slurp the file? I would guess that
you don't have to do that at all.
All I want to do is find and store the values "Aword" and "Aword
Anotherword" from the array and set the index to that array element
where I found the above pattern.
Are you now saying that you want to store in a variable at which line
respective word (or pair of words) was found? Then a hash may be what
you want:
my %hash;
open FILE, 'file.txt' or die $!;
while (<FILE>) {
$hash{$.} = $1 if /^\s*(\w+(?:\s*\w+)?)\s*$/;
}
close FILE;
print "Line $_: $hash{$_}\n" for sort { $a <=> $b } keys %hash;
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>