[Raleigh-talk] Issues after converting bash to Perl - way to call a config file that contains if/then logic

Mike South msouth at gmail.com
Tue Feb 22 06:48:58 PST 2011


On Tue, Feb 22, 2011 at 1:50 AM, John Ricker <sephtin+pm-talk at gmail.com>wrote:

> On Tue, Feb 22, 2011 at 2:08 AM, Mike South <msouth at gmail.com> wrote:
>
>>
>>
>> On Mon, Feb 21, 2011 at 10:21 PM, John Ricker <sephtin at gmail.com> wrote:
>>
>>>
[snip]


> Re: the "bash'ish" way... was the only way I could come up with that didn't
> load everything regardless of what I needed... other than splitting up each
> theme into separate files, which I'm trying to avoid.
> My failure was with use(), since it required path at runtime (using lib)
> which I couldn't provide at compile time as the path is a variable defined
> in the file.
> I DID attempt require, but wasn't able to pass the variable to the config
> file.  I must have been doing something wrong because after checking Mike's
> example and switching things back for require, it seems to be working...
>  I'll probably comment it out, and try what seems to be the most recommended
> method... just hashing everything, and reading it that way... good learning
> experience at the very least...   :)
>
>
I just looked through the example and realized I had forgotten to cut part
of it out.  Sorry if this was confusing.  The "$which_dir" variable should
be removed completely, in favor $theme_sub_dir.  The idea was to show that
$theme_sub_dir wasn't known until runtime (since it's being pulled in from
the environment), and demonstrate how to require() something from that
dynamically-determined dir.  The $which_dir variable was from when I was
making sure I was right about how I thought it worked :).  Change that
section to look like this:

#comment this out
#our $which_dir = 'bob';

$which_config = 'one';
#$which_config = 'two';

my $theme_sub_dir = $ENV{theme} || die "set theme in the env like this:
theme='test' $0\n";

my $full_path_to_require = "/Users/msouth/$theme_sub_dir";
die "there is not a directory called $full_path_to_require" unless -d
$full_path_to_require;
push @INC, $full_path_to_require;;

#just use the file name since @INC has been modified
#require "$which_dir/set_up_bob.pl";

require "set_up_bob.pl"; # require "$full_path_to_require/set_up_bob.pl"
would work here, too


mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/raleigh-talk/attachments/20110222/4cacd348/attachment.html>


More information about the Raleigh-talk mailing list