in reply to How can i read the lines and store them in an array like following fashion?

You could always gather up the data into a list of array refs, each pointing at the block data elements. If the raw data file is small enough, you could always slurp the whole thing, and process it as below.

#!/usr/bin/perl use strict; use warnings; undef $/; my @blocks = map { [ split /\n/ ] } ( split /(?=ITEM)/, ( map { s/#.*\n//; $_ } <DATA> )[0] ); print "$_\n" for @{ $blocks[1] }; # print block no. 2 __DATA__ #This is the ITEM file ITEM NO:1 [aaa] 111 [bbb] 222 [ccc] 333 ITEM NO:2 [ddd] 444 [eee] 555 [fff] 666 ITEM NO:3

Yeah, it's kinda golfy.

Hope this helped,
-v.

"Perl. There is no substitute."
  • Comment on Re: How can i read the lines and store them in an array like following fashion?
  • Download Code

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.
A reply falls below the community's threshold of quality. You may see it by logging in.