in reply to Printing a dollar sign..

I don't quite know what you are doing, besides unnecessarily stringifying your vars. The first example you quote does work, as does the second. All I can suggest is that you go on to eval the string at some point so the $123.45 is evaluated by perl - perl will see the $123 as a var (undef value) and thus leave you with .45 I suspect you have not got warnings turned on as it would be warning you about interpolating an undef string. I suggest you use warnings;. This works as you can see.

$_srp_price = 123.456789; $cost = sprintf "\$%.2f", $_srp_price; $string = "Cost $cost\n"; print $string; __DATA__ Cost $123.46

cheers

tachyon

Replies are listed 'Best First'.
Re^2: Printing a dollar sign..
by powerhouse (Friar) on Aug 26, 2004 at 20:48 UTC
    I figured it out. You guys were right. :o) I did have an eval in there. I had it do a search for variables and switch them out of the HTML:
    $_template_code =~ s/(\$[a-zA-Z0-9\{\'\}_]+)/ eval($1) /ge; # Switch a +ll the $variables... (This is the WHOLE html document, $_page_content + is in the main table for the main content. This will switch any vari +ables with the data.
    I fixed it by adding this to it:
    $_template_code =~ s/(\$[a-zA-Z0-9\{\'\}_]+)/ eval($1) /ge if $1; # Sw +itch all the $variables...
    adding the 'if $1' fixed it because the variable is undefined so it won't switch it.

    Thank you guys for pointing me in the write direction :)
    thx,
    Richard

      Consider HTML::Template or at least using its syntax. Using $VAR in templates and eval is not exactly best practice.

      cheers

      tachyon