- 论坛徽章:
- 307
|
本帖最后由 sunzhiguolu 于 2017-07-08 13:22 编辑
perl abc.pl a b
#!/usr/bin/perl
use strict;
use warnings;
sub Load{
local @ARGV = pop;
my $fb = [];
while(<>){
my @aT = split;
/\A\s*[a-z]/i ? push(@{$fb}, [@aT]) : push(@{$fb->[-1]}, @aT ? @aT : undef);
}
$fb;
}
my $fb = Load(pop);
my ($pos, $fa) = (-1, []);
print("case ");
<>;
my @aFix = ('COL1', 'COL2', 'COL3', 'P_CODE', 'M_SRC', 'M_FEC', 'SEC_TYP');
local $" = " AND ";
while(<>){
if(/\A(\d+)\Z/){
$pos = $1;
next;
}
next if(!defined($fb->[$pos]));
print("when ");
my @aT = split;
my @aOut = ();
foreach(0 .. $#aT - 1){
next if(!defined($fb->[$pos][$_]));
my $v = $fb->[$pos][$_];
my $pair = $aT[$_] eq 'D' ? [$aFix[$_], 0] : [$aFix[$_], $v =~ /\D/ ? "'$v'" : $v];
push(@aOut, sprintf("%s = %s", @$pair));
}
print("@aOut THEN $fb->[$pos][-1]\n");
}
print("END\n");
|
|