Re: DBI/SQL question



Robert Hicks wrote:
I have a large array of numbers that I need to use in an update SQL
statement using a "like" clause.

my @nums = ( 123 456 789 ); # it is much larger

foreach my $num (@nums) {
$dbh->do(q{update table_name set item_desc1 = item_desc2 where
equip like # I draw a blank here
}

I am not sure how to use the $num in a like since a like is '%' and it
I do '%$num' that won't be interpolated.

The '%' isn't the issue.

Use qq instead of q. Check the documentation in: perldoc perlop

This should help you see the difference.

my $num = 22;
print q{ equip like '%$num' }, "\n";
print qq{ equip like '%$num' }, "\n";
.



Relevant Pages

  • Re: DBI/SQL question
    ... foreach my $num { ... equip like # I draw a blank here ... I am not sure how to use the $num in a like since a like is '%' and it ...
    (comp.lang.perl.misc)
  • Re: DBI/SQL question
    ... statement using a "like" clause. ... foreach my $num { ... like # I draw a blank here ... I am not sure how to use the $num in a like since a like is '%' and it I do '%$num' that won't be ierpolated. ...
    (perl.beginners)
  • DBI/SQL question
    ... I have a large array of numbers that I need to use in an update SQL statement using a "like" clause. ... foreach my $num { ... equip like # I draw a blank here ... I am not sure how to use the $num in a like since a like is '%' and it I do '%$num' that won't be interpolated. ...
    (perl.beginners)
  • DBI/SQL question
    ... statement using a "like" clause. ... foreach my $num { ... equip like # I draw a blank here ... I am not sure how to use the $num in a like since a like is '%' and it ...
    (comp.lang.perl.misc)
  • Re: Lazy evaluation?
    ... foreach $num { ... really sure if up to the point of lazy evaluation. ... The above (foreach list) *is* lazy evaluated (at least ... actually required for the printfunction which is not what perl does. ...
    (comp.lang.perl.misc)