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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Evaluating variables read from a file 1

Status
Not open for further replies.

faelord

Technical User
Jan 4, 2002
6
GB
I have a simple menuing program where the items for the menu are read from a file in the following format:

user level| link text | link url , eg
Code:
0|Shop|cgi-bin/vc_shop.pl?id=$id&level=$level&where=shop

It is read in using the following:
Code:
while ($atext=<OFILE>)
	{
	@item=split(/\|/,$atext);
	$ulevel=$item[0];
	$utext=$item[1];
	$ulink=$item[2];
	$add=&quot;<a href=\&quot;$ulink\&quot;>$utext</a><br>&quot;;
	$text=$text.$add;
	}
close(OFILE);
return $text;
However the variables such as $id are reproduced in the final url ($add) in their unevaluated form. How can I force them to be replaced by their values?
 
# insert this after $ulink is established
# put any variable that might be needed in the parens
foreach $varname qw( id level ... ) {
# use a reference to the variable in question
$vv = $$varname;
$ulink =~ s/\$$varname/$vv/;
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top