in reply to Re^2: Changing parameters
in thread Changing parameters

My offering only changes one setting at a time.

Yes, there is something better, but what it is exactly depends on how complex your parameters are, what kind of validations you'll want to be doing on them, and so on. But the baisic thing about configuration is that if they are in a data file, you can give them to someone who isn't familiar with Perl syntax for editing and they have less chance of breaking things if they leave off a semicolon somewhere.

Very often INI-style config files win over thanks to their simplicity. Take a look over at CPAN -- they have plenty of modules that handle this format. My personal favorite is Config::Tiny, but shop around. (If your config data is flat, for example, you might not like Config::Tiny's "_" level.)

For more complex data — long text, arrays, maps and so on — YAML is a nice choice. It also has a Perl module to handle it. See if you like it better! (Some people dislike its sensitivity to indentation.)

Replies are listed 'Best First'.
Re^3: Changing parameters
by sparkel (Acolyte) on Nov 29, 2004 at 17:00 UTC
    Hi gaal,

    Thanks for those suggestions. That is exactly the reason I had the parameter file, so that other people don't need to open up the script files inorder to change values. Also, all the parameters used in different scripts can be found in one place. I'll look up those modules you have suggested.

    I did try your script and it only changes one variable. Please tell me how I can change both i and j (and many more) at one go in the command line.

    Thanks.

      I won't, because it would probably be quicker for you to run the one-liner several times (it's already parametized) than it would be for me to rewrite it to do multiple values at once. And it won't really stay a one-liner afterwards :)

      But if you insist, I can tell you how I'd do it!

      First, instead of ($var, $val) = @ARGV, which maps one pair only, I'd use an associative array to slurp in multiple pairs:

      %updates = @ARGV;

      Now, instead of $var I need to iterate over the values of %updates, and instead of $val I need to say $updates{whatever-the-curent-var-name-is}.

      Probably this has taken me enough time already, so please assemble the parts yourself :)

        Thank you so much :o)

        I looked at the configuration file and now I am planning on changing the parameter file to do it that way which seems much cleaner and a nicer way.

        Thanks for the suggestions gaal.