Andre_br has asked for the wisdom of the Perl Monks concerning the following question:

Hello folks

This is probably the easiest for you guys; IŽm not very familiar with building my own modules, so here it goes: The code:

my $fte_user_id = ""; eval "use FatalsToEmail ( Client => $fte_userna +me )"; $fte_username = "client"; # Just to test, this is when I get the user +name from mysql argh! # suppose hereŽs the error. print "Content-type: text/html\n\n"; print "Hi";
I need my FatalsToEmail.pm to remember the $fte_username has just been assigned "client", you know?

Thanks a lot folks

Replies are listed 'Best First'.
Re: Defining variable for module, but IŽll only have it later
by sauoq (Abbot) on Oct 01, 2005 at 23:57 UTC

    It looks to me like you need your FatalsToEmail module to take a reference to a scalar and you need to pass it a reference to $fte_username.

    Your package might look something like this...

    package FatalsToClient; use vars qw($client); sub import { my $pkg = shift; my %args = @_; $client = $args{Client}; } 1;
    And you'd use that something like this...
    my $fte_username = ""; use FatalsToClient (Client => \$fte_username); $fte_username = "client"; print $$FatalsToClient::client, $/; $fte_username = "something else"; print $$FatalsToClient::client, $/;
    Please recognize that this code is just for illustration. You'll want yours to be somewhat cleaner I expect.

    -sauoq
    "My two cents aren't worth a dime.";