*警告我是Perl的相对新手* 该代码可能比需要的时间更长。
我正试图爆炸COBOL工作存储,当我进入二维(或更多)二维数组时,它只会执行第一个循环。 (X点会检查我们是否不处理已收集的任何内容就退出子程序),但是如果我已经深了一层,只会循环一次
我有一个递归子例程,该例程传递每次需要分解的工作存储阵列。
注意:我有一个小的限制,那就是客户端仅在perl 5.8.8上使用
sub process_array(@) {
my $array_in_ref = $_[0];
my @array_in = @$array_in_ref;
my $rec_no = 0;
my $pushing = FALSE;
my $push_level = 0;
my $push_cnt;
my @occurs;
foreach my $rec (@array_in) {
my @line = split /\|/, $rec;
my $level = $line[2];
if ($pushing) {
if ( $level gt $push_level ) {
push @occurs, $rec;
next;
}
else {
for ( my $i = 1 ; $i le $push_cnt ; $i++ ) {
push @indices, $i;
process_array( \@occurs );
pop @indices;
}
$pushing = FALSE;
@occurs = ();
$push_level = 0;
}
}
# break the data up
my $occurs_cnt = $line[8];
if ( $occurs_cnt eq "" ) {
$name = fixname($name);
#print the data
if ( $PIC_type ne "MANY" ) { $file_pos = $file_pos + $length; }
next;
}
if ( $PIC_type eq "MANY" ) {
$name = fixname($name);
#print the data
$pushing = TRUE;
$push_cnt = $occurs_cnt;
$push_level = $level;
next;
}
for ( my $i = 1 ; $i le $occurs_cnt ; $i++ ) {
push @indices, $i;
$name = fixname($name);
#print the data
pop @indices;
if ( $PIC_type ne "MANY" ) { $file_pos = $file_pos + $length; }
}
}
my $x = scalar(@occurs);
if ( $pushing && $x > 0 ) {
my $i;
#POINT X
for ( $i = 1 ; $i le $push_cnt ; $i++ ) {
push @indices, $i;
process_array( \@occurs );
pop @indices;
}
$pushing = FALSE;
@occurs = ();
$push_level = 0;
}
}
发生3次,然后发生2次 我应该得到6行(1,1)(1,2)(2,1)(2,2)(3,1)(3,2)
我只得到(1,1)(1,2)的第一个循环,它会经过一会儿掉落
我已经调试了代码,在POINT X中返回后,$ 1和$ push_cnt仍然应该是它们。
似乎for循环已经失去了堆栈。
答案 0 :(得分:2)
我以前从未见过Perl像COBOL那样编写。我不想花太多时间来分析那些奇怪的代码,但是我建议您的问题是import PlaygroundSupport
import Alamofire
class LoadingViewController: UIViewController {
private lazy var activityIndicator = UIActivityIndicatorView(style: .gray)
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
activityIndicator.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(activityIndicator)
NSLayoutConstraint.activate([
activityIndicator.centerXAnchor.constraint(equalTo: view.centerXAnchor),
activityIndicator.centerYAnchor.constraint(equalTo: view.centerYAnchor)
])
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// We use a 0.5 second delay to not show an activity indicator
// in case our data loads very quickly.
DispatchQueue.main.asyncAfter(deadline: .now() + 0.0) { [weak self] in
self?.activityIndicator.startAnimating()
}
}
}
// methods for adding and removing child view controllers.
extension UIViewController {
func add(_ child: UIViewController, frame: CGRect? = nil) {
addChild(child)
if let frame = frame {
child.view.frame = frame
}
view.addSubview(child.view)
child.didMove(toParent: self)
}
func remove() {
// Just to be safe, we check that this view controller
// is actually added to a parent before removing it.
guard parent != nil else {
return
}
willMove(toParent: nil)
view.removeFromSuperview()
removeFromParent()
}
}
class MyViewController : UITabBarController {
override func loadView() {
let view = UIView()
view.backgroundColor = .white
let label = UILabel()
label.frame = CGRect(x: 150, y: 200, width: 200, height: 20)
label.text = "Hello World!"
label.textColor = .black
view.addSubview(label)
self.view = view
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let loadingViewController = LoadingViewController()
add(loadingViewController, frame: view.frame)
AF.request("http://www.youtube.com").response { response in
print(String(describing: response.response))
loadingViewController.remove()
}
}
}
// Present the view controller in the Live View window
PlaygroundPage.current.liveView = MyViewController()
运算符用于比较文本,而不是数字。尝试改用le
。您还有另一个<=
循环遇到同样的问题。