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.
In reply to Re: How can i read the lines and store them in an array like following fashion?
by Velaki
in thread How can i read the lines and store them in an array like following fashion?
by sanjay nayak
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |