How to add variables to strings?

Y

yusuf

Hi,

I want to construct a SQL statement which consists of a string added to
some information stored in variables. But its not adding the text of
the variable to the first part of the string, just storing the value of
the variable:

$statement = "select * FROM logarama WHERE timestamp > ". $T[4]+1
 
P

Paul Lalli

yusuf said:
Hi,

I want to construct a SQL statement which consists of a string added to
some information stored in variables. But its not adding the text of
the variable to the first part of the string, just storing the value of
the variable:

$statement = "select * FROM logarama WHERE timestamp > ". $T[4]+1

Running the above through -MO=Deparse,-p gives us:

$ perl -MO=Deparse,-p -e'$statement = "select * FROM logarama WHERE
timestamp > " . $T[4]+1;'
($statement = (('select * FROM logarama WHERE timestamp > ' . $T[4]) +
1));
-e syntax OK

As the above shows, . has a higher precedence than +. So you are
contatenating $T[4] to the string literal, and then adding 1 to the
result. Put parentheses around your addition expression:

$statement = "select * FROM logarama WHERE timestamp > " . ($T[4]+1);

Paul Lalli
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,197
Messages
2,571,041
Members
47,643
Latest member
ashutoshjha_1101

Latest Threads

Top