我有以下Perl脚本
$filters = "SELECT lead_id, status, user, title, first_name, last_name, city, phone_number FROM vicidial_list , vicidial_lists WHERE vicidial_list.list_id = vicidial_lists.list_id";
$stmtA = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'asterisk' AND TABLE_NAME = 'vicidial_list'";
$sthA = $dbhA->prepare( $stmtA ) or die "preparing: ", $dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$counter = 0;
$columns = ();
while ( my @row = $sthA->fetchrow_array ) {
# GET the name columns by pos
$column = "@row[0] \n";
# Check if exists the name columns
if ( index( $filters, @row[$counter] ) > -1 ) {
$find = @row[$counter];
$replace = "vicidial_list." . @row[$counter];
# Replace the name column
$filters =~ s/$find/$replace/g;
}
}
print $filters . "\n\n";
#Close connection
$sthA->finish();
在有评论# Check if exists the name columns
的部分中,我想知道一些字符串之前和之后的内容。
例如,如果我选择MY NAME IS CRISTOPHER
,则NAME
会返回MY
之前的IS
,然后是select *
from(
select *, row_number() over (partition by id order by id,issuingstate desc) as rn
from #temp
where (case when PrimaryLocation ='Y' then 1
when PrimaryLocation ='N' and locationstate = issuingstate then 1
when PrimaryLocation ='N' and issuingstate is NULL then 1
else 0 end) = 1
) a
where rn = 1
。
答案 0 :(得分:0)
如果你的问题是关于在字符串中找到一个模式,在perl中,那么一个答案可能是正则表达式:
my $string='MY NAME IS';
my $pattern='NAME';
if ($string =~ /$pattern/) {
print "Before: $`\n";
print "After: $'\n";
}
另请参阅特殊RE variables的完整列表。