in reply to How do I...Conditional hash value
First off, beware the "= vs. eq vs. ==" bug. Remember that = does an assignment, == compares numeric values, and eq compares string values. Having said that, what you're probably looking for is the ternary ?: operator (documented in perlop). I'd write what you're looking for like this:
my %required; $required{path} = ($ENV{HTTP_HOST} eq 'www.shrum.net') ? 'g:/websites/shrum.net/' : 'd:/users/http/html/';
Then again, if you have several keys to set, you're probably better off doing:
"One word of warning: if you meet a bunch of Perl programmers on the bus or something, don't look them in the eye. They've been known to try to convert the young into Perl monks." - Frank Willisonmy %required; if ($ENV{HTTP_HOST} eq 'www.shrum.net') { # We now know which # platform we're on... $required{path} = 'g:/websites/shrum.net/'; $required{someotherkey} = 'some other string'; } else { $required{path} = 'd:/users/http/html/'; $required{someotherkey} = 'some different string'; }
In Section
Seekers of Perl Wisdom