in reply to Printing a dollar sign..

What do you think is in $_srp_price? Can we see the code that sets it?

I'm guessing that you have code something like:

$_srp_price = "$4.95"; print $_srp_price;

Here's an example

$ perl -le '$_ = "$4.95"; print' .95

Adding the -w flag tells us what is going wrong

$ perl -wle '$_ = "$4.95"; print' Use of uninitialized value in concatenation (.) or string at -e line 1 +. .95

Perl is looking for a variable called $4 and failing to find it.

The fix is to either use single quotes

$ perl -wle '$_ = q($4.95); print' $4.95

Or to escape the dollar sign

$ perl -wle '$_ = "\$4.95"; print' $4.95
--
<http://www.dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

Replies are listed 'Best First'.
Re^2: Printing a dollar sign..
by powerhouse (Friar) on Aug 26, 2004 at 20:33 UTC
    Actually it's called out of a database. Here is the code:

    $db_s_id = param("scid"); my $sth = $dbh->prepare (qq{ SELECT * FROM `prods` WHERE ? IN (sub +_cat1,sub_cat2,sub_cat3) AND `u` = "1"}); $sth->execute($db_s_id); my $_cell_cnt = 0; while($row = $sth->fetchrow_hashref()) { $_cell_cnt++; $_srp_price = $row->{srp}; $_table_data .= qq~ <tr valign="middle"> <td align="center"> <a href="javascript:;" onclick="window.open('$_img +url/ShowPic.cgi?pid=$row->{pid}','POPUP','status=no,menu=no,location= +no,resizable=yes,scrollbars=yes,width=400,height=400,top=25,left=25') +; return false" onmouseover="window.status='Opens in New window'; ret +urn true" onmouseout="window.status=''; return true">~; if(-e "/home/<<user_replaced>>/www/images/prod_images/$row->{pid}. +gif") { $_table_data .= qq~<img src="$_imgurl/images/prod_images/$row- +>{pid}.gif" width="75" alt="$row->{name}" border="0">~; } else { $_table_data .= qq~<img src="$_imgurl/images/no_image.gif" wid +th="75" alt="No Image Yet Available. Sorry." border="0">~; } $_table_data .= qq~</a> </td> <td align="center"> <a href="javascript:;" onclick="window.open('$_url +?pg=$in{pg}&view=showFullItem&pid=$row->{pid}&nw=1$inc_sess_id','FULL +VIEW','status=no,menu=no,location=no,resizable=yes,scrollbars=yes,wid +th=400,height=400,top=25,left=25'); return false" onmouseover="window +.status='Opens in New window'; return true" onmouseout="window.status +=''; return true">$row->{name}</a><br>~; if($row->{instock} && ($row->{instock} == 1)) { $_stock_message = "In Stock"; $_table_data .= qq~[<a href="$_surl?pg=products&view=cart&do=a +dd_prod&pid=$row->{pid}$inc_sess_id">Add to Cart</a>] ~; } else { $_stock_message = qq~<font class="stand_out">Out of Stock</fon +t>~; } if($_logged_in && ($_logged_in == 1)) { $_table_data .= qq~[<a href="$_url?pg=products&view=wish_list& +do=add&id=$row->{pid}$inc_sess_id">Add to Wish List</a>]~; } $_table_data .= qq~<br> $row->{desc}<br> Item Number: $row->{pid}~; if($row->{itemSize} && ($row->{itemSize} ne "")) { $_table_data .= qq~ .:. Size: $row->{itemSize}~; } $_table_data .= qq~ $_stock_message~; if($row->{uom} && ($row->{uom} ne "")) { $_table_data .= qq~ .:. Unit of Measure: $row->{uom}~; } $_table_data .= qq~ </td> <td align="center" valign="top" style="padding-top: 5p +x"> ~ . escapeHTML(sprintf("%.2f", "$_srp_price")) . q +q~ </td> </tr> ~; } $sth->finish();
    I will try the code you suggested and see if it works, I'll post the results. BTW, I don't eval the $_page_content which is the variable that $_table_data gets put into. I do eval $vars{} variables that contain <code></code> tags. That is the only ones I use eval on.

    thx,
    Richard