in reply to Dynamic variables and strict

My instinct here would be to make a hash.
#untested code! my %conf = (); foreach (`. /my/config.cfg; set`) { chomp; my ($var,$val) = /^\s*(.*?)\s*=\s*(.*)/; $conf{$var} = $val; }
This would tell you (and anyone who reads your code!) that values accessed using the hash came from outside the program. It also seems to clean up uninitialized varible issues... I don't know, it just seems right to use a hash to relate keys to values.

~dewey

Replies are listed 'Best First'.
Re^2: Dynamic variables and strict
by FunkyMonk (Bishop) on May 02, 2007 at 22:35 UTC
    As dewey said, hashes are the way to go. As long as you remember to check that s/// matched.

    Instead of

    my ($var,$val) = /^\s*(.*?)\s*=\s*(.*)/; $conf{$var} = $val;
    I'd use
    if (/^\s*(.*?)\s*=\s*(.*)/) { $conf{$1} = $2; } else { die "slowly and painfully"; }