Naser Ali wrote:
>
> Naser Ali wrote:
> >
> >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 all who responded. Much appreciated. It works, but please allow me
> to sight an example. The data pattern looks like this;
>
> Aword
> Some Alphanumeric long string columnized format
> Some Alphanumeric long string columnized format
> Some Alphanumeric long string columnized format
>
> Aword
> Some Alphanumeric long string columnized format
> Some Alphanumeric long string columnized format
> Some Alphanumeric long string columnized format
>
> Aword
> Some Alphanumeric long string columnized format
> Some Alphanumeric long string columnized format
> Some Alphanumeric long string columnized format
>
> Aword Anotherword
> Some Alphanumeric long string columnized format
> Some Alphanumeric long string columnized format
> Some Alphanumeric long string columnized format
>
> Aword
> Some Alphanumeric long string columnized format
> Some Alphanumeric long string columnized format
> Some Alphanumeric long string columnized format
>
> ..............And so and so forth
>
> I have to slurp the file first in an array
No you don't. Use paragraph mode to read one paragraph at a time.
> in order to do some clean up and
> parsing before I can get to this. As you al know when I slurp a file each
> line is stored in individual array element.
> 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.
>
> Hope this helps.
>
> My code never worked and here is how I was doing it.
> Note: Please note that this is just a quicky to print the element of the
> array containting a word or two words and just simply printing them.
$/ = ''; # set paragraph mode
while ( <FILE> ) {
my ( $index, $paragraph ) = split /\n/, $_, 2;
# do some clean up and parsing
}
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>