Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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

by Velaki (Chaplain)
on Oct 19, 2006 at 10:57 UTC ( [id://579325]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://579325]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-18 13:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found