Knowing not too much from perl, I would like to remember the last paragraph of Jeremiah:

> Keep in mind that interpolation is work, so using one of the
> single quotes
> strings which does not search your string for variables to
> replace is going
> to be higher performance than the double quoted version, although the
> difference may be a little or a lot depending on how many
> times the string
> is interpreted (if it is in a loop or something).

If performance is a problem, don't forget this.

John Trammell wrote:
From 'perldoc perldata':

  Variable substitution inside strings is limited to scalar
  variables, arrays, and array or hash slices.  (In other
  words, names beginning with $ or @, followed by an optional
  bracketed expression as a subscript.)

You can check this from the command line:

  % perl -le 'print "$s -- @s -- %s"'
  --  -- %s

So the '%' isn't the issue here.  The issue is certainly the (mis)use of
join(), as was pointed out by a previous poster.



-----Original Message-----
From: Jeremiah Gowdy [mailto:[EMAIL PROTECTED] Sent: Monday, July 25, 2005 9:14 AM
To: Siegfried Heintze; mysql@lists.mysql.com
Subject: Re: How to use Like Clause in Perl? Works fine in MySQL control center!

When you use double quotes for strings in Perl, Perl looks through your strings for variables like $foo, and replaces them with the current value of $foo. This is called interpolation. When you use single quotes, it considers your string a literal.

So when you use double quotes, you need to escape any special characters like $ % " or @. When you use single quotes, the only character you have to worry about is '. Here are ways you could make this string work.

Double quotes with special characters escaped (due to interpolation)

"SELECT 'David!' LIKE '\%D\%v\%'"

Single quotes with double quote usage for the SQL quoting (no escaping required)

'SELECT "David!" LIKE "%D%v%"'

Single quotes with single quotes escaped for the SQL quoting

'SELECT \'David!\' LIKE \'%D%v%\''

Keep in mind that interpolation is work, so using one of the single quotes strings which does not search your string for variables to replace is going to be higher performance than the double quoted version, although the difference may be a little or a lot depending on how many times the string is interpreted (if it is in a loop or something).


----- Original Message ----- From: "Siegfried Heintze" <[EMAIL PROTECTED]>
To: <mysql@lists.mysql.com>
Sent: Friday, July 22, 2005 4:03 PM
Subject: How to use Like Clause in Perl? Works fine in MySQL control center!



I'm having trouble getting the like clause to work. It

seems to work fine
in
the MySQL Control Center 9.4.beta. I'm using MySQL 4.0.23-debug.

use DBH;
my $sth = DBH->prepare("SELECT 'David!' LIKE '%D%v%'");
$sth->execute();
my $row;
print join(@$row,",")."\n" while ($row = $sth->fetch);


This does not print a "1" in perl. It just prints a ",".

I've posted a query on this in [EMAIL PROTECTED] with no luck.

Anybody have any suggestions?
Thanks,
Siegfried

--
Nuno Pereira

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to