SPUG: Exporting from BEGIN block

Creede Lambard creede at rrauto.com
Thu Feb 15 14:26:47 CST 2001


OK, here's the scenario. I want to be able to export a variable from a BEGIN
block. Is there any reasonable way to do it?

Here's my code so far:

BEGIN
{
    if (eval { use Finance::YahooQuote; } )
        { $hasQuote = 1; }
    else
        { $hasQuote = 0; }
}

print $hasQuote;

I get a result of 0 whether I use Finance::YahooQuote (which I have on my
system) or Foo::Bar or similar nonexistent modules.

Now here's what I'm really trying to do: I'm writing a Visual Basic app
(yeah, I know, but at least I get to use Perl for the heavy lifting) that
will, among other things, check our company's stock quotes. I want to check
to see if Finance::YahooQuote is present on whatever machine I'm installing
the app on, and if it's not present, set a flag that makes the stock ticker
portion of the app inaccessible. The O'Reilly PerlCOM object for VB will
export variables, so if something like the above worked I could do

if objPerlCOM.hasQuote then
    lblStockQuote.visible
end if

As I understand it, the eval code to check for the module has to be in a
BEGIN block because it has to be checked at compile time instead of run
time. Since the BEGIN block is executed before anything else starts running,
I don't have an opportunity to define any variables before it runs. So, here
I am. Any suggestions?


 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
  Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/





More information about the spug-list mailing list