in reply to how to put perl variables inside html tags

You are not clear whether this patch of html is the output from your program or snipped from your Perl script itself. And if it is from your Perl script, it is not clear how you are printing this out:

Are you using CGI for this?
Is it in a 'here doc'?
Are you using a print statement for each line?

The value $afld[3] can be printed or interpolated just fine. The only thing to be careful of is how to incorporate the double-quotes in your html and still interpolate the array value.

The problem of course is that if you want to interpolate the value in a string, the string has to be specified in a double-quotish manner. But if you just enclose it in double-quotes, the html double-quotes mess things up. There are a variety of approaches:

print qq[<a href="mailto:$afld[3]">]; or print '<a href="mailto:' . $afld[3] . '">';
...to give just two examples.

Note also: there is nothing between <a href="mailto:$afld[3]"> and the </a> tag. If this is an accurate snippet, the mailto: link is there but no link text is being displayed because you have specified nothing.

Update: If you have a managable number of these values to interpolate, this approach works fine. If you are doing more ambitious things with lots of interpolated values and other fancy programmatic stuff, check into the embedding/templating solutions that have been proposed.

Replies are listed 'Best First'.
Re: Re: how to put perl variables inside html tags
by Anonymous Monk on Jul 28, 2001 at 03:21 UTC
    I am outputtin this html page thru ther perl script by using print <<HTML here all html code HTML i tried putting <a href="mailto:$afld[3]">$afld[3]</a> but even it didn't work although when i am removing <a> </a> totally, and just printing $afld[ +3] its printing,but without a link.
      Odd... Somewhere along the line you have done something you are not accounting for. At about this point, I would stick the following into the middle of your 'print <<HTML' block:
      print <<HTML ...stuff that's already there ------BEGIN TEST------- Here is afld3: |$afld[3]| <a href="mailto:someone@somewhere.com">mail link 1</a> <a href="mailto:someone@somewhere.com">$afld[3]</a> <a href="mailto:$afld[3]">mail link 2</a> <a href="mailto:$afld[3]">$afld[3]</a> **What we want** -------END TEST------- ...more stuff that's already there HTML
      Then run it and look at the html code this prints (not just what shows up visible in the browser) to see what is happening.