Hi Meir.

I think that you are confusing perl's eval and DBI eval.
Your code is using perl's eval,
which is invalid for #1, (so you get undef and can check $@ for error
string)
and for #2, the evaluated string is $sql_date, so you get the date inside
it.

if you want to have SQL command to the DB, check the DBI module:
https://metacpan.org/pod/DBI
I think you are looking for the 'do' command.

Shmuel.


On Fri, Aug 1, 2014 at 12:15 AM, Meir Guttman <[email protected]> wrote:

> Please Perlers,
>
> The following script:
>
> <code>
> use strict;
> use warnings;
>
> my $sql_date = '2014-7-31';
>
> my $raw_string_1 = 'WHERE col = $sql_date';
> my $raw_string_2 = '$sql_date';
>
> my $evaled_1 = eval $raw_string_1; # yields 'undef'
> my $evaled_2 = eval $raw_string_2; # yields '2014-7-31'
>
> print "First: $evaled_1\nSecond: $evaled_2\n";
> </code>
>
> Yields 'undef'  (and a concatenation warning) for $evaled_1 and '2014-7-31'
> for $evaled_2. Why???
>
> Notes:
> 1) I need the first form to work.
> 2) I am well aware of the DBI/DBD 'prepare()' with place holders. Mine is
> not the case for it, since 'col' is a run-time column name and so it cannot
> be assigned a place holder.
> 3) Neither can the date be assigned to a place holder. It is not always a
> date. The "WHERE" clause is an arbitrary complex compilation read from an
> INI file and various parts in it must be substituted by Perl variables
> values, also only determined at run-time.
>
> Thanks!
> Meir
>
> _______________________________________________
> Perl mailing list
> [email protected]
> http://mail.perl.org.il/mailman/listinfo/perl
_______________________________________________
Perl mailing list
[email protected]
http://mail.perl.org.il/mailman/listinfo/perl

Reply via email to