假设我在 perl 字符串变量中有一个 sql 查询:
select a from table one union select b from table two union select c from table three union select d from table four union select e from table five union select f from table six union select g from table seven union select h from table eight
在上面的文本中,我有八个由联合分隔的单独查询。
我希望其中一半存储在一个变量中,另一半存储在另一个变量中。
我知道应该一直有 8 个查询,中间有 7 个联合。我尝试了以下脚本,但无法正常工作。
#!/usr/bin/perl
use strict;
use warnings;
my $var="select a from table one union select b from table two union select c from table three union select d from table four union select e from table five union select f from table six union select g from table seven union select h from table eight";
$var=~m/(.*union{3})(.*)/g;
print $1;