Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable variables? 3

Status
Not open for further replies.

rdcss

Programmer
Jun 24, 2004
17
US
I have the following in my script:

foreach $name ( param() ) {
$value=$dbh->quote(param($name));
print "$name = $value ";
}


I need each $name to also be listed as variable $$name... is there any way to tell it to do that? I tried adding a line
$$name=$name
but that did not work.

Right now, $name=name and $value='value' (value is correct, name needs to be $name rather than just name).

I hope I am stating clearly enough what I need.
 
${$name} = $name

___________________________________
[morse]--... ...--[/morse], Eric.
 
What are you trying to accomplish? The "variable variable names" is almost always better done with a hash.

$params{$name} = $value;

________________________________________
Andrew
 
Ok, here's the whole entire subroutine.

Code:
sub update_closing {
my ($name, $value);
foreach $name ( param() ) {
	$value=$dbh->quote(param($name));
	print "$name = $value ";
}

#	$dateclosed=$dbh->quote(param('dateclosed'));
#	$houseadd=$dbh->quote(param('houseadd'));
#	$sellfn=$dbh->quote(param('sellfn'));
#	$sellln=$dbh->quote(param('sellln'));
#	$sellstr=$dbh->quote(param('sellstr'));
#	$sellcity=$dbh->quote(param('sellcity'));
#	$sellst=$dbh->quote(param('sellst'));
#	$sellzip=$dbh->quote(param('sellzip'));
#	$buyfn=$dbh->quote(param('buyfn'));
#	$buyln=$dbh->quote(param('buyln'));
#	$buystr=$dbh->quote(param('buystr'));
#	$buycity=$dbh->quote(param('buycity'));
#	$buyst=$dbh->quote(param('buyst'));
#	$buyzip=$dbh->quote(param('buyzip'));
#	$mls=$dbh->quote(param('mls'));
#	$debcomm=$dbh->quote(param('debcomm'));
#	$patcomm=$dbh->quote(param('patcomm'));
#	$lister=$dbh->quote(param('lister'));
#	$surveyor=$dbh->quote(param('surveyor'));
#	$closingatt=$dbh->quote(param('closingatt'));	
#	$pestco=$dbh->quote(param('pestco'));
#	$soldprice=$dbh->quote(param('soldprice'));

#print "$dateclosed, $houseadd, $sellfn, etc";

	$sth=$dbh->do("UPDATE closings 
	SET dateclosed=$dateclosed,houseadd=$houseadd,sellfn=$sellfn,sellln=$sellln,sellstr=$sellstr,sellcity=$sellcity,sellst=$sellst,sellzip=$sellzip,buyfn=$buyfn,buyln=$buyln,buystr=$buystr,buycity=$buycity,buyst=$buyst,buyzip=$buyzip,mls=$mls,debcomm=$debcomm,patcomm=$patcomm,lister=$lister,surveyor=$surveyor,closingatt=$closingatt,pestco=$pestco,soldprice=$soldprice	
	WHERE id=$id")
	or bail_out("Can't update closing");
	view_closings();
}

The part #'d out is the part I'm attempting to replace.
Using that part, I get an error because some of them do not have information.
With it as it is above, I get an error because there are no variables (i.e. $houseadd is not set) although the values are there.

Help?
 
Work any better with placeholders?
Code:
sub update_closing {
    $sth=$dbh->prepare("UPDATE closings SET
        dateclosed=?,
		houseadd=?,
		sellfn=?,
		sellln=?,
		sellstr=?,
		sellcity=?,
		sellst=?,
		sellzip=?,
		buyfn=?,
		buyln=?,
		buystr=?,
		buycity=?,
		buyst=?,
		buyzip=?,
		mls=?,
		debcomm=?,
		patcomm=?,
		lister=?,
		surveyor=?,
		closingatt=?,
		pestco=?,
		soldprice=?
        WHERE id=?")

    $sth->execute(
		param('dateclosed'),
		param('houseadd'),
		param('sellfn'),
		param('sellln'),
		param('sellstr'),
		param('sellcity'),
		param('sellst'),
		param('sellzip'),
		param('buyfn'),
		param('buyln'),
		param('buystr'),
		param('buycity'),
		param('buyst'),
		param('buyzip'),
		param('mls'),
		param('debcomm'),
		param('patcomm'),
		param('lister'),
		param('surveyor'),
		param('closingatt'),
		param('pestco'),
		param('soldprice'),
		$id)
    or bail_out("Can't update closing");
    view_closings();
}

________________________________________
Andrew
 
THANK YOU!!! That worked perfectly!! You have been MOST helpful. I appreciate you taking the time to answer.

Gratefully,
Dawn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top