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 つの個別のクエリがあります。
それらの半分をある変数に保存し、残りの半分を別の変数に保存したい。
私は、常に 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;