Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Skipping data on file read

by injunjoel (Priest)
on Jun 13, 2008 at 21:56 UTC ( [id://692021]=note: print w/replies, xml ) Need Help??


in reply to Skipping data on file read

Greetings, Though this does not solve your problem think of it as a different approach to it. I would suggest setting the input record separator to a different value to get your file to be read in differently. Assuming your example file is representative of your input...
#!/usr/bin/perl -w use strict; #of course this assumes the example file is in the exact #format expected. The following line is basically the #line containing a lone 'c' at the beginning and a whole #bunch of spaces (your comment cards). #remember that $/ can't handle regexp... though it sure #would be cooler if it did. local $/ = "c + "; while (<DATA>){ print "\n=====chunk start=======\n"; print $_; print "\n=====chunk stop=======\n"; } #from the example data you gave. __DATA__ m8 92234.30c 0.0071 92235.30c 0.9300 92238.30c 0.06289 + 8016.30c 2.0 42000.30c 2.5 + c + c BeO(2.86) Axial Reflector TD=3.01 / 95%=2.86 + m9 4009.30c 0.5 8016.30c 0.5 + mt9 beo.01t + c + c BeO(?AllgenCalc) Radial Reflectpr TD=3.01 / 95%=2.86 + m10 4009.30c 0.5 8016.30c 0.5 + mt10 beo.01t + c + c He/Xe(.0218) (72/28) ~.55 mol/L at 300K,1.38MPa, 39.6 g/mol + m11 2004.30c 0.7 + 54124.30c 0.00027 54126.30c 0.00027 54128.30c 0.00576 + 54129.30c 0.07932 54130.30c 0.01224 54131.30c 0.06354 + 54132.30c 0.08067 54134.30c 0.03132 54136.30c 0.02661 + c + c Sodium(0.929) RoomTemp = .97 g/cc, at melt = .929 g/cc + c Liquid = .929 - .000244*(t-371) (t in K) Handbook Ch&Ph + m12 11023.30c 1.0 $ Na (.929 g/cc) frozen/voi +d c + c Lithium(.515) RoomTemp = .534 g/cc, at melt = .515 g/cc + c Liquid = .515 - .000101*(t-454) (t in K) Handbook Ch&Ph
So essentially you can get the file read in in chunks and deal with each chunk with your regexp. Oh and here is the output from above.
=====chunk start======= m8 92234.30c 0.0071 92235.30c 0.9300 92238.30c 0.06289 + 8016.30c 2.0 42000.30c 2.5 + c + =====chunk stop======= =====chunk start======= c BeO(2.86) Axial Reflector TD=3.01 / 95%=2.86 + m9 4009.30c 0.5 8016.30c 0.5 + mt9 beo.01t + c + =====chunk stop======= =====chunk start======= c BeO(?AllgenCalc) Radial Reflectpr TD=3.01 / 95%=2.86 + m10 4009.30c 0.5 8016.30c 0.5 + mt10 beo.01t + c + =====chunk stop======= =====chunk start======= c He/Xe(.0218) (72/28) ~.55 mol/L at 300K,1.38MPa, 39.6 g/mol + m11 2004.30c 0.7 + 54124.30c 0.00027 54126.30c 0.00027 54128.30c 0.00576 + 54129.30c 0.07932 54130.30c 0.01224 54131.30c 0.06354 + 54132.30c 0.08067 54134.30c 0.03132 54136.30c 0.02661 + c + =====chunk stop======= =====chunk start======= c Sodium(0.929) RoomTemp = .97 g/cc, at melt = .929 g/cc + c Liquid = .929 - .000244*(t-371) (t in K) Handbook Ch&Ph + m12 11023.30c 1.0 $ Na (.929 g/cc) frozen/voi +d c + =====chunk stop======= =====chunk start======= c Lithium(.515) RoomTemp = .534 g/cc, at melt = .515 g/cc + c Liquid = .515 - .000101*(t-454) (t in K) Handbook Ch&Ph + =====chunk stop=======
Does that make sense?

-InjunJoel
"I do not feel obliged to believe that the same God who endowed us with sense, reason and intellect has intended us to forego their use." -Galileo

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-03-29 09:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found