perl - Perl variables access problem with recursive call sub
问题描述
I need to convert the database to SQL. I write it on perl. It's here:
P.S. Simplifyed
#!/usr/bin/perl
use utf8;
use strict;
use warnings;
my @tables = (
['clients', ['id'], 'id', '',
[['accounts', ['id'], '', 'id_client', 0]]
]
);
sub ProcessTables {
my ($tbl, $id_value) = @_;
my ($i, $i2, $sth);
my @arr;
my $arr_count = $#$tbl;
for ( $i=0; $i<=$arr_count; $i++ ) {
if ( $tbl->[$i]->[4] != 0) {
@arr = @{$tbl->[$i]->[4]};
ProcessTables( \@arr, 'blablalba' );
};
}
};
ProcessTables(\@tables);
When I get into the procedure a second time (after the line @arr = ....) by the passed parameters and access to them, there are no problems. Everything is smooth and beautiful. Everything changes radically on the line "if ( $tbl->[$i]->[4] != 0)". After that, it seems that I did not go here. All variables refer to the data that I saw when I first entered this procedure. Before the call "if," all links pointed to an array with data "accounts". After the call, they began to point to the "clients" again. Please tell me what is the matter? Why it happens?
P.S. I debug it under linux. This is output:
DB<2>
main::ProcessTables(TestRecurce2.pl:19):
19: my $arr_count = $#$tbl;
DB<2>
main::ProcessTables(TestRecurce2.pl:20):
20: for ( $i=0; $i<=$arr_count; $i++ ) {
DB<2>
main::ProcessTables(TestRecurce2.pl:21):
21: if ( $tbl->[$i]->[4] != 0) {
DB<2> p $tbl
ARRAY(0x5593be5baba0)
DB<3> p $tbl->[$i]
ARRAY(0x5593be5fbf78)
DB<4> p $tbl->[$i]->[4]
0
DB<5> n
Debugged program terminated. Use q to quit or R to restart,
use o inhibit_exit to avoid stopping after program termination,
h q, h R or h o to get additional info.
解决方案
推荐阅读
- ios - 为什么在覆盖自定义单元格的 setSelected 方法后,表格视图单元格每次在滚动时出现时都会被选中?
- swift - 无法转换“MyEnum”类型的值
' 到预期的参数类型 'MyEnum<_>' - python - Python C++浮点数学表示错误
- tensorflow - 我使用 tf.data.TFRecordDataset 读取 tfcord ,为什么我读取的数据不正确
- php - 用于两个独立查询的 PHP mysqli_fetch_assoc
- sql-server - SSMS:即使启用了选项,也禁用了“生成更改脚本”
- javascript - 使用 fo:external-graphic XSL 从外部 http URL 加载图像
- spring-boot-admin - 成功登录后 Spring Boot Admin Server 重定向到 login.html
- shell - 如何在 shell 脚本中自动读取命令?
- c++ - 我可以避免包括
如果我不使用它的功能?