Before everybody starts with the screaming, wailing, and gnashing of teeth,
I would suggest that this is not the best way to go about doing this.  I
think everybody tries it at one point in their coding lives, but it will
lead you down the path to illegible code.  Check out 'perldoc perllol' for
some more complicated data structures that you can use to do what you are
trying to do...

-----Original Message-----
From: rory oconnor [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 01, 2002 3:13 PM
To: perl
Subject: dynamic variable declaration?


I'm trying to do something that i'm not sure is even possible.  I want
to cycle thru an array of MySQL fieldnames and dynamically declare
variables based on those fieldnames. 

I can create the array of fieldnames no problem, by just using
"describe" with DBI.

But I can't figure out the declaration part.  THis is what i've tried...

foreach $i (@fieldlist) {
        $$i = $session->get_query_value('$i');
        }

That doesn't work, although that's the gist of what I'm after. 
Fieldnames are like "order_id", bill_fname", "ship_lname", etc.  

If I were to hard-code these declarations, I would have about 40 lines
that look like:

$order_id = $session->get_query_value('order_id');
$customer_id = $session->get_query_value('customer_id');
$bill_prefix  = $session->get_query_value('bill_prefix');
$bill_fname = $session->get_query_value('bill_fname');

The $session-> bit is a function that grabs data of the same name as my
fieldnames from an outside sessionfile.

I am just trying to avoid having to hardcode this stuff in there,
because a) it's alot of code and b) the fieldnames/session variables
will grow and I don't want to have to edit the script every time.  

Any help is appreciated!

Thanks,

rory



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to