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!

Addition in concatenation problem

Status
Not open for further replies.

bacoms

Programmer
Jun 14, 2008
6
As a relative newbie to perl and CGI, can someone please tell me why the following resolves ok;

use constant DATEWIDTH => 86;
use constant PRICEWIDTH => 60;
my($earliestWidth) = DATEWIDTH + PRICEWIDTH;

print "earliest-cell {width: " . $earliestWidth . "px;}\n";
print "date-cell {width: " . DATEWIDTH . "px;}\n";
print "price-cell {width: " . PRICEWIDTH . "px;}\n";

but the following doesn't;

print "earliest-cell {width: " . DATEWIDTH + PRICEWIDTH . "px;}\n";

Running cgi script in command prompt generates error;

Argument "earliest-cell {width: 86" isn't numeric in addition (+) at fakedheader.cgi line 39.
60px;}

How come I can add the two constants together in the assignment statement but not in the concatenation. (It's nothing to do with constants as I get the same error when I change the constants declarations to variables.)

I suspect this is something simple that I have forgotten or misunderstood but it has got me baffled (but it is Monday morning).

Thanks in advance for any help.

Bryan
 
Hi,

I knew it would be something simple. It's all working fine now.

Many thanks for your help.

Bryan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top