Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: build array of geometry data

by BrowserUk (Pope)
on Feb 10, 2003 at 17:17 UTC ( #234174=note: print w/ replies, xml ) Need Help??


in reply to build array of geometry data

If your files get very large, then slurping them into memory to parse can be memory intensive. This solution processes the file line-by-line and uses a running buffer to parse it.

Code

#! perl -slw use strict; my @arrays; my $buf =''; while($buf .= <DATA>) { push(@arrays, [ split(' ',$1) ]) , $buf = $2 while $buf =~ /\[([^]]+)\](.*$)/g; } print do{ local $"=','; "[@$_]" } for @arrays; __DATA__ [1 1 1 1 1 1] [4 4 4 4 4 4] [ 123 123 123 123 123 123 123 123 123 ] "P" [ -1 1 1 1 1 -1 1 1 1 ]

Output

<
c:\test>234118 [1,1,1,1,1,1] [4,4,4,4,4,4] [123,123,123,123,123,123,123,123,123] [-1,1,1,1,1,-1,1,1,1]

Examine what is said, not who speaks.

The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (10)
As of 2016-07-28 13:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What is your favorite alternate name for a (specific) keyboard key?


















    Results (255 votes). Check out past polls.