Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Defining variable for module, but IŽll only have it later

by Andre_br (Pilgrim)
on Oct 01, 2005 at 23:19 UTC ( [id://496690]=perlquestion: print w/replies, xml ) Need Help??

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.";
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://496690]
Approved by sauoq
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-23 17:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found