in reply to Re: using .profile in perl
in thread using .profile in perl

ok here's some background on the current situation: We have 2 instances of our application setup on 1 server, but using different ports to use the application. So, rather than having two different logins for each instance, we have created 2 different .profile (ofcourse they both contain different names) The .profile basically sets up the environment values for each instance.
I have a perl script that needs to be run on both instances..but I want to just have 1 version of the script, rather than duplicate the script on both instances. Also, some of the code within script is interrelated...for eg. I may want to call another script within this one, and use that information to do something else on the other instance. That is the reason, I want to source the .profile within the perl script...such that I want to change the environment half way through the perl script.
I hope this helps in your understanding of our problem. Sorry if i'm doing a bad job at explaining, but I'm really new to scripting.

Replies are listed 'Best First'.
Re^3: using .profile in perl
by GrandFather (Saint) on Feb 20, 2006 at 02:44 UTC

    You could do something like the following (using ENV rather than foo):

    use strict; use warnings; use Data::Dump::Streamer; my %foo = (a => 'b', c => 'd'); my @stack; my %newFoo = (x => 'b', y => 'd'); push @stack, {%foo}; %foo = %newFoo; print "Using \%newFoo\n"; Dump (\%foo); # do stuff with temporary foo %foo = %{pop @stack}; print "restored original \%foo\n"; Dump (\%foo);

    Prints:

    Using %newFoo $HASH1 = { x => 'b', y => 'd' }; restored original %foo $HASH1 = { a => 'b', c => 'd' };

    DWIM is Perl's answer to Gödel