By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,693 Members | 1,972 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,693 IT Pros & Developers. It's quick & easy.

help me for writing query in perl

P: 3
hi....

i want to write the query
select * from user where name = "richard"; in perl

the string richard i have taken that in the variable $name.

i have written the query as below
Expand|Select|Wrap|Line Numbers
  1. $sth = $dbh -> prepare('select * from user where name = "$name"');
  2.  
is this correct way of writing in perl?
Oct 1 '08 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 126
hi....
$sth = $dbh -> prepare('select * from user where name = "$name"');
In Perl, " " interpolates variables, ' ' doesn't, so putting a " " inside a ' ' won't cause the variables to be read. Try this instead:

Expand|Select|Wrap|Line Numbers
  1. $sth = $dbh->prepare("SELECT * FROM user WHERE name ='$name' ");
  2. #or, if you need double quotes in the query:
  3. $sth = $dbh->prepare("SELECT * FROM user WHERE name = \"$name\"");
  4. #or
  5. $sth = $dbh->prepare('SELECT * FROM user WHERE name = "' . $name . '"');
  6.  
Hope this helps.
Oct 1 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.