一个for循环的问题
时间:2010-07-30
来源:互联网
本帖最后由 东方补白 于 2010-07-30 12:31 编辑
正在看别人写的代码,有一段不太明白,请教一下大家。
下面一段代码的目的是处理从文本中读取出来的内容,如果在某行匹配了</rpc-reply>字符串,就删除其之后的内容。
但是如下的部分是不是多了一个'{'?
复制代码
还是说这种写法等同于如下代码,即$i=0是在for循环之外。
复制代码
完整的部分
复制代码
多谢各位了。
正在看别人写的代码,有一段不太明白,请教一下大家。
下面一段代码的目的是处理从文本中读取出来的内容,如果在某行匹配了</rpc-reply>字符串,就删除其之后的内容。
但是如下的部分是不是多了一个'{'?
- for (my $j = $i +1; $j < 0; $j++) {
- {
- delete $outArray[$j];
- }
- $i = 0;
- }
- for (my $j = $i +1; $j < 0; $j++) {
- delete $outArray[$j];
- }
- $i = 0;
- sub session_cmd {
-
- my ($session, $command) = @_;
-
- my $out = '';
- my $err = '';
- my $exit = '' ;
- my @outArray;
- my $i;
- my $counter = 0;
- my $nodata = 1;
- my $rc;
- my $foundCmd = 0;
-
-
- $session->clear_accum();
-
- print $session "$command\n";
-
-
- $rc = $session->expect( $timeout, '-re', $prompt, '-re', 'vty\)#' );
- if (!defined($rc)) {
- $err = "never got prompt from host!\n";
- undef $out ;
- $exit = "";
- print SINK "Timed out in $timeout seconds for $command\n";
- # print SINK "timed out on command: $command\n";
- print "timed out on command: $command\n";
- }
- else
- {
-
- $nodata = 0;
- # print SINK "Recieved response in $timeout seconds for $command\n";
- $out = $session->exp_before;
-
- @outArray = split( /\n/, $out);
- for ( $i = 0; $i < 5; $i++) {
- $foundCmd = 1 if ($outArray[$i] =~ /$command/);
- $foundCmd = 1 if ($outArray[$i] =~ /syntax\s+error/) ;
- }
-
-
-
- if ( $command =~ /xml/i)
- {
-
- delete $outArray[0];
- for ( $i = -5; $i < 0; $i++) {
- if ($outArray[$i] =~ /<\/rpc-reply>/)
- {
- for (my $j = $i +1; $j < 0; $j++) {
- {
- delete $outArray[$j];
- } # end for
- $i = 0;
- } # end for ( $i =
-
- } # end if ($outArray
-
- }
- }
- $out = join("\n", @outArray);
-
- }
-
-
- my $retryCounter = 0;
- while ( ($retryCounter < 5) && (0 == $foundCmd))
- {
- $rc = $session->expect( 1, '-re', $prompt, '-re', 'vty\)#' );
- if (!defined($rc)) {
- print "DEBUG: no residual data $retryCounter\n";
- }
- else
- {
- $nodata = 0;
- # print SINK "Recieved response in $timeout seconds for $command\n";
-
- my $out1 = $session->exp_before;
- my @out1Array = split( /\n/, $out1);
- for ( $i = 0; $i < 5; $i++) {
- $foundCmd = 1 if ($out1Array[$i] =~ /$command/);
- $foundCmd = 1 if ($out1Array[$i] =~ /syntax\s+error/) ;
- }
-
- if ( $command =~ /xml/i)
- {
-
- delete $out1Array[0];
- for ( $i = -5; $i < 0; $i++) {
- if ($out1Array[$i] =~ /<\/rpc-reply>/)
- {
- for (my $j = $i +1; $j < 0; $j++) {
- {
- delete $out1Array[$j];
- } # end for $j
- $i = 0;
- } #end for (my $j = $i +1; $j < 0; $j++) {
-
- } # end if ($out1Array[$i] =~ /<\/rpc-reply>/)
-
- } # end for ( $i = -5; $i < 0; $i++) {
-
-
-
-
- } #end if ( $command =~ /xml/i)
- $out1 = join("\n", @out1Array);
- $out = $out . "\n" . $out1;
- }
- $retryCounter = $retryCounter +1;
- } # end while $retryCounter
- # $out = $session->exp_before;
- #print SINK "Recieved response (unknown)in $counter seconds for $command\n";
-
- if ($foundCmd)
- {
- print SINK "DEBUG: retryCounter: $retryCounter found command $command\n";
- print "DEBUG: retryCounter: $retryCounter found command $command\n";
- }
- else
- {
- print SINK "DEBUG: $prompt did not find command $command\n";
- print "DEBUG: $prompt did not find command $command\n";
- }
-
-
-
- $session->clear_accum();
- return ($out, $err, $exit);
- }
作者: 东方补白 发布时间: 2010-07-30
观望 学习
作者: OnlyForStudy 发布时间: 2010-07-30
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28