i'm trying to build variables dynamically from data passed to a
subroutine. i pass a text value (a field from a database) and want to
build an associated variable name by appending a prefix to the field
name ($oob_<fieldname>). that constructed variable would then acquire
the value of the variable as defined prior to calling the sub.
################################
#!/usr/bin/perl
my $oob_state = "IL";
my $oob_lata = "732";
my $oob_name = "SomeName";
build_vars("state", "lata", "name");
sub build_vars
{
while (my $field = shift)
{
my $variable = '$oob_' . $field;
my $var = \$variable;
my $var2 = $$var;
print "\nfield = \"$field\"\nvariable = \"$variable\" = \"$var\"
($var2)\n";
}
}
################################
which gives the following results:
field = "state"
variable = "$oob_state" = "SCALAR(0x804ce58)" ($oob_state)
field = "lata"
variable = "$oob_lata" = "SCALAR(0x804ce58)" ($oob_lata)
field = "name"
variable = "$oob_name" = "SCALAR(0x804ce58)" ($oob_name)
what i want is this:
field = "state"
variable = "$oob_state" = "IL"
field = "lata"
variable = "$oob_lata" = "732"
--
field = "name"
variable = "$oob_name" = "SomeName"
manipulations like these have always given me headaches; all thanks
for any help.
joe
since this is a gmail account, please verify the mailing list is
included in the reply to addresses
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>