niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » Perl
How to add variables to strings?
Post new topic   Reply to topic Page 1 of 1 [2 Posts] View previous topic :: View next topic
Author Message
yusufm
*nix forums addict


Joined: 27 Feb 2006
Posts: 52

PostPosted: Tue Jul 18, 2006 7:01 pm    Post subject: How to add variables to strings? Reply with quote

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
Back to top
Paul Lalli
*nix forums Guru


Joined: 10 Jun 2005
Posts: 1089

PostPosted: Tue Jul 18, 2006 7:14 pm    Post subject: Re: How to add variables to strings? Reply with quote

yusuf wrote:
Quote:
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
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [2 Posts] View previous topic :: View next topic
The time now is Thu Jan 08, 2009 7:03 am | All times are GMT
navigation Forum index » Programming » Perl
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Quoting, variables, and xterm graftonfot@yahoo.com shell 2 Thu Jul 20, 2006 2:26 pm
No new posts Question on comparing to variables containing integers huub Perl 14 Thu Jul 20, 2006 11:02 am
No new posts Interpret variables in strings in ksh greenhakan@gmail.com shell 2 Wed Jul 19, 2006 2:03 pm
No new posts Retrieve ext. variables in python program alfa1234 python 7 Wed Jul 19, 2006 7:59 am
No new posts How to add variables to strings? yusufm Perl 6 Tue Jul 18, 2006 7:02 pm

Loans | School Girl Costumes | Credit Cards | Best Credit Cards | Loans
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0969s ][ Queries: 16 (0.0321s) ][ GZIP on - Debug on ]