ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl-win32-users
perl-win32-users
Re: why doesn't this work?
by Eric Amick other posts by this author
Sep 27 2004 4:41PM messages near this date
view in the new Beta List Site
AW: HTML Form data into Word Document | why doesn't this work?
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
Perl-Win32-Users@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved