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;
 
Y

yusuf

Sorry about the multiple posts, the line is:

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

Paul Lalli

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

What did you expect? What did you actually get? Can you post some
actual code (what's above won't compile)?

The above compiles just fine if you don't chop off the OP's beginning
dollar-sign:
$ perl -c -e'$statement = "select * FROM logarama WHERE timestamp > " .
$T[4]+1;'
-e syntax OK

Please make sure your newsreader isn't assuming that $ means "beginning
of a quoted line"

Paul Lalli
 
T

Ted Zlatanov

On 18 Jul 2006, (e-mail address removed) wrote:

Ted Zlatanov wrote: > On 18 Jul 2006, (e-mail address removed) wrote: >
statement = "select * FROM logarama WHERE timestamp > ". $T[4]+1;

What did you expect? What did you actually get? Can you post some
actual code (what's above won't compile)?

The above compiles just fine if you don't chop off the OP's beginning
dollar-sign:
$ perl -c -e'$statement = "select * FROM logarama WHERE timestamp > " .
$T[4]+1;'
-e syntax OK

You're right. Gnus cut it off because I hit Enter too fast when it
asked if $ was a quote char.

In any case, the code is incomplete and my original questions are
valid, minus "won't compile." Who knows what $T holds, and what the
OP expects.
Please make sure your newsreader isn't assuming that $ means "beginning
of a quoted line"

Thanks.

Ted
 
P

Paul Lalli

Ted said:
In any case, the code is incomplete and my original questions are
valid, minus "won't compile." Who knows what $T holds, and what the
OP expects.

I disagree. I think the OP was plenty clear in his original post:
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

The value of $T is irrelevant, since the code does not use $T. The
value of @T is also irrelevant, as the question is about why the value
of $T[4] plus 1 does not get added to the string. The OP said exactly
what he expected: "adding the text of the variable to the first part of
the string". (The form of the request leads me to believe the OP is
not a native English-speaker, which more than excuses (to me)
grammatical errors). Anyone who runs the code sees what happens
instead - $statement gets the value of 1.

There are a multitude of un-clear posts in this newsgroup. I do not
believe this was one of them.

Paul Lalli
 
T

Ted Zlatanov

In any case, the code is incomplete and my original questions are
valid, minus "won't compile." Who knows what $T holds, and what the
OP expects.

I disagree. I think the OP was plenty clear in his original post:
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

The value of $T is irrelevant, since the code does not use $T. The
value of @T is also irrelevant, as the question is about why the value
of $T[4] plus 1 does not get added to the string.

Yes. Thanks for catching my mistake. I was thinking of @T, of
course, and I missed the obvious bug as you point out.
The OP said exactly what he expected: "adding the text of the
variable to the first part of the string". (The form of the request
leads me to believe the OP is not a native English-speaker, which
more than excuses (to me) grammatical errors). Anyone who runs the
code sees what happens instead - $statement gets the value of 1.

I see. The question was difficult for me to understand and I missed
the real problem, but I'm glad you got it.

Ted
 

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