Perl Monk, Perl Meditation | |
PerlMonks |
Re^3: Multiply the numbers in a text fileby aaron_baugher (Curate) |
on May 10, 2015 at 06:34 UTC ( [id://1126235]=note: print w/replies, xml ) | Need Help?? |
Now that you've provided some sample data, we can accomplish something. You still need to make your requirements more concrete, though. What qualifies as a "small negative value"? All negative values, or ones below a certain value? If these should be converted to "0 or -9999", which should it choose? If some should be 0 and some should be -9999, based on what criteria? If you hired me to write this script, I would need you to answer those questions. To get you started, you can skip the first six lines by simply reading and writing them:
Then proceed with your filtering on the remaining lines. I'll guess that you want all negative values smaller than -0.1 replaced with 0 or -9999 alternatively, assume that values are space-delimited, and continue:
If you want your changes to replace the original file, the best way to do that is to write to a new file and then copy it over the old file when you're finished. You can do that copy manually, or make that part of your script after you've tested enough to be confident that it will work correctly. Aaron B.
In Section
Seekers of Perl Wisdom
|
|