anjaana78 has asked for the wisdom of the Perl Monks concerning the following question:

Hi there...
my question is pretty simple but i am stuck with it. i have to pass qoutes in the string. like for example:
$query = "select zipcount from table where id = emailid and address != +"" and first != "" group by c.z5" ;
the problem here is when i am giving qoutes it is breaking up with inner empty qoutes of the string and not printing the adress !="". Hope any some one is gonna help.

thanks

Replies are listed 'Best First'.
Re: how do i pass qoutes to in the string.
by Anonymous Monk on May 10, 2001 at 17:52 UTC
    You can use two methods:
    $query = 'select zipcount from table where id = emailid and address != +"" and first != "" group by c.z5' ;
    or escape the quotations
    $query = "select zipcount from table where id = emailid and address != +\"\" and first != \"\" group by c.z5" ;
    but if it is a SQL select, the server will usually accept this:
    $query = "select zipcount from table where id = emailid and address != +'' and first != '' group by c.z5";
    Regards,

    Peter

Re: how do i pass qoutes to in the string.
by arturo (Vicar) on May 10, 2001 at 18:00 UTC

    In addition to using the single quotes and escaping your quotes, there are also a few operators that help: q{ STRING } acts as single quotes around the string (variables won't be interpolated), and qq{ STRING } acts as double quotes around the string. See perldoc perlop for more info on the 'q' branch =)

Re: how do i pass qoutes to in the string.
by thpfft (Chaplain) on May 10, 2001 at 21:02 UTC

    Hi. two options out of several possible: use qq or escape the "s within the string.

    $query = qq|select zipcount from table where id = emailid and address +!= "" and first != "" group by c.z5|;

    or

    $query = "select zipcount from table where id = emailid and address != + \"\" and first != \"\" group by c.z5";

    qq|| - the double quote operator - does exactly the same as "", but is not closed by a ". Very useful for keeping html (and SQL, i guess) readable within perl. See perlop for more.

    Actually, in your example you could just use single quotes to enclose the select string, since you're not interpolating anything, but i expect you'll end up with a variable in there at some point.