Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
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.


Comment on Re: build array of geometry data
Select or Download Code

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 examining the Monastery: (13)
As of 2014-08-21 13:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (135 votes), past polls