jm wrote: > 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"; > } > } > ################################
Use a hash: my %oob = ( state => 'IL', lata => 732, name => 'SomeName', ); If you don't think that you need a hash then be aware that what you are trying to do is actually using a hash anyways (the %main:: hash.) John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>