1

I have an unusual requirement. I have a big config /perl file in which I would like to change the value of one variable before my run. To avoid manually finding the variable and changing it's value, I would like to write a perl script to change the name of the variable. Is that possible to do this without parsing every single line of big perl file, creating a temporary copy and overwriting old file.

5
  • 2
    Why not pass arguments to the script? ie Getopt::Long Commented Aug 6, 2013 at 21:26
  • Why is your post about changing the name of a variable but the title is about changing the value of a variable? Commented Aug 6, 2013 at 21:28
  • @kjprice - The big perl file is more like a configuration file. Not exactly a perl file. Sorry I should have mentioned it Commented Aug 6, 2013 at 21:31
  • @mob - It is changing the value of a variable. I have rephrased in a better way. Thanks! Commented Aug 6, 2013 at 21:31
  • 3
    For a dozen different ways to do this, see stackoverflow.com/a/2308092/176646 Commented Aug 6, 2013 at 21:33

1 Answer 1

1

Something is parsing this file at some point, right? Give it a list of things to substitute and you can have it only do the substitutions when it needs it. This avoids a big pre-startup overhead and if the config file is sparsely used, will result in a faster overall run.

So just make the thing reading it look for certain patterns to substitute in and a file (or passed in on the command line or environment variables, or...) for the values it should use and go from there.

If you don't have control over the parser, then there's not much to do. You could one-time pre-process the config file to determine EXACTLY where the substitutions need to be and write a faster processor, since it won't have to do any string parsing for regular expressions, just moving a bunch of bytes as fast as your computer can move them to the new file with the substitutions in place.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.