Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
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?
[Discipulus]: good morning vietnam!
[Discipulus]: but there is some perl workshop somewhere? I notice many high level monks disappeared.. we can make PM a squat in the meantime ;=)
[karlgoethebier]: Discipulus: Mmh, who disappeared?
[marto]: morning all
[shmem]: perl -lE '$_="odd mornin";($o=$_)=~ s/^|$/g/g;say$o'
[Eily]: Hi monks o/

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2017-06-27 08:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (600 votes). Check out past polls.