On Mon, 27 Sep 2004 12:05:10 -0700, you wrote: >================ >test script: >================ >use strict; >use testlib; > >print("Env Var 'Oracle' is set to '$ENV{Oracle}'\n"); >callme(); > >================ >test library (testlib.pm): >================ >use strict; > >if ($ENV{Oracle}) { > sub callme {print("Version 1\n");} > } >else { > sub callme {print("Version 2\n");} > }
Normal subroutine definitions occur at compile time, so the second definition overrides the first before the code even executes. You can do this instead: if ($ENV{Oracle}) { eval 'sub callme {print("Version 1\n");}' } else { eval 'sub callme {print("Version 2\n");}' } or this: if ($ENV{Oracle}) { $callme = sub {print("Version 1\n");} } else { $callme = sub {print("Version 2\n");} } or even this: if ($ENV{Oracle}) { *callme = sub {print("Version 1\n");} } else { *callme = sub {print("Version 2\n");} } In any case, you will need either an argument list or an ampersand when calling callme(), since Perl won't know the type at compile time. (The second case would need $callme->() or &$callme.) -- Eric Amick Columbia, MD _______________________________________________ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs