List:General Discussion« Previous MessageNext Message »
From:Jeremiah Gowdy Date:July 25 2005 2:14pm
Subject:Re: How to use Like Clause in Perl? Works fine in MySQL control center!
View as plain text  
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" <siegfried@stripped>
To: <mysql@stripped>
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 beginners-perl@stripped with no luck.
>
> Anybody have any suggestions?
> Thanks,
> Siegfried
>
> Here is DBH.pm. Below that is my original post in beinners-perl@stripped.
>
>
> package DBH;
> use DBI;
> require Exporter;
> our @ISA = qw(Exporter);
> our @EXPORT = qw(DBH); # Symbols to be exported by default
> our @EXPORT_OK = qw(); # Symbols to exported by request
> our $VERSION = 0.1;
>
>
> our $dbh;
> sub DBH{
>    unless ( $dbh && $dbh->ping ) {
>        $dbh = DBI->connect ( 'dbi:mysql:dbname=hotjobs;host=SALES', 'xyz',
> 'xyz' ) ;
>        die DBI->errstr unless $dbh && $dbh->ping;
>    }
>    return $dbh;
> }
>
> 1;
> ----------------------------------------------------------------------------
> --------------------------------------------------------
>
>
> The following code works with Activestate perl 8.4/MySQL. If I comment the
> second line, however, it does not work. No error messages and no results.
>
> If I use the MySQL Enterprise console and type in my first SELECT 
> statement
> that includes the LIKE clause, it works.
>
> I'm stumped. There must be something strange with that "%", but I cannot
> figure it out.
> Anyone got any suggestions?
>
> Siegfried
>
> my $sJobTitle = "SELECT sName FROM keywords ORDER BY sName WHERE sName 
> LIKE
> '%'";
>  $sJobTitle = q[SELECT sName FROM keywords ORDER BY sName];
>
>  my $sth = DBH->prepare($sJobTitle);
>  $sth->execute();
>  my $row;
>  while ($row = $sth->fetch){
>    push @sResult,"<li>".join( "", @$row)."</li>\n";
>  }
>
>
> -- 
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    http://lists.mysql.com/mysql?unsub=1
>
> 

Thread
missing ibd files on upgrade of mysql from 4.1.9 to 4.1.12aJason Pyeron4 Jul
  • Re: missing ibd files on upgrade of mysql from 4.1.9 to 4.1.12aGleb Paharenko4 Jul
    • Re: missing ibd files on upgrade of mysql from 4.1.9 to 4.1.12aJason Pyeron4 Jul
      • Re: missing ibd files on upgrade of mysql from 4.1.9 to 4.1.12aGleb Paharenko5 Jul
        • Re: missing ibd files on upgrade of mysql from 4.1.9 to 4.1.12aJason Pyeron5 Jul
        • Re: missing ibd files on upgrade of mysql from 4.1.9 to 4.1.12aJason Pyeron5 Jul
      • Documentation on Like clauseSiegfried Heintze22 Jul
        • Re: Documentation on Like clausePaul DuBois23 Jul
          • How to use Like Clause in Perl? Works fine in MySQL control center!Siegfried Heintze23 Jul
            • Re: How to use Like Clause in Perl? Works fine in MySQLcontrol center!Frank Bax23 Jul
              • Alternatives to performing join on normalized joins?Siegfried Heintze24 Jul
                • Re: Alternatives to performing join on normalized joins?SGreen25 Jul
                  • RE: Alternatives to performing join on normalized joins?Siegfried Heintze26 Jul
                    • How to select first 1000 records like MySQL Control Center 0.9?Siegfried Heintze26 Jul
                      • Re: How to select first 1000 records like MySQL Control Center 0.9?Peter Brawley26 Jul
            • Re: How to use Like Clause in Perl? Works fine in MySQL control center!Jeremiah Gowdy25 Jul
RE: How to use Like Clause in Perl? Works fine in MySQL control center!John Trammell25 Jul
  • Where did my disk space go?Siegfried Heintze4 Aug
    • Re: Where did my disk space go?Sebastian4 Aug
      • RE: Where did my disk space go?Siegfried Heintze4 Aug
  • Re: How to use Like Clause in Perl? Works fine in MySQL control center!Nuno Pereira8 Aug
RE: Where did my disk space go?SST - Adelaide)4 Aug
  • RE: Where did my disk space go?Siegfried Heintze4 Aug
    • RE: Where did my disk space go?David Logan4 Aug
      • How to delete log files? Was: RE: Where did my disk space go?Siegfried Heintze5 Aug
        • Re: How to delete log files? Was: RE: Where did my disk space go?Gleb Paharenko5 Aug
RE: How to delete log files? Was: RE: Where did my disk space go?SST - Adelaide)5 Aug
  • RE: How to delete log files? Was: RE: Where did my disk space go?Ron Thomas5 Aug
RE: How to use Like Clause in Perl? Works fine in MySQL control center!John Trammell8 Aug