哪位有时间帮我看一下这段代码,谢谢了

哪位有时间帮我看一下这段代码,谢谢了

哪位有时间帮我看一下这段代码,谢谢了
1 哪位有时间帮我解释一下这段代码,我参考一下 谢谢了

[quote]
#!/usr/bin/perl


# main page using frames to create menu on the left and functions on the right.
#

$VERSION="4.08 ";

&maininit( "snmp.ini" );

&mainframework( "snmp.ini" );

sub maininit (@) {
my($snmpini) = @_;
my(@test,$i,$n,$key,$val);

## put CGI ENV variables in global var:
##把计算机图形接口环境变量放在球形的 var里面:

if( $ENV{'SCRIPT_NAME'} ne '' )
{
if( rindex( $ENV{'SCRIPT_NAME'}, '/' ) > 0 )
{
@test = split( '/', $ENV{'SCRIPT_NAME'} );
$inivar{'script'} = $test[$#test];
$#test--;
$inivar{'cgidir'} = &convertdir( '/', @test );
$inivar{'cgidir'} = substr( $inivar{'cgidir'}, 1 );
}
else
{
$inivar{'script'} = $ENV{'SCRIPT_NAME'};
$inivar{'cgidir'} = "";
}
if( index( $ENV{'PATH'}, "\\" ) > 0 )
{
$inivar{'slash'} = "\\";
}
}
if( $inivar{'httpdir'} eq '' )
{
if( $ENV{'SCRIPT_FILENAME'} ne '' )
{
$inivar{'httpdir'} = substr( $ENV{'SCRIPT_FILENAME'}, 0, index( $ENV{'SCRIPT_FILENAME'}, $inivar{'cgidir'} ) -1 );
}
elsif( $ENV{'PATH_TRANSLATED'} ne '' )
{
$inivar{'httpdir'} = substr( $ENV{'PATH_TRANSLATED'}, 0, index( $ENV{'PATH_TRANSLATED'}, $inivar{'cgidir'} ) -1 );
}
}
## Work cgidir: http + cgi directory
$inivar{httpcgidir} = &convertdir( $inivar{'slash'}, $inivar{'httpdir'}, $inivar{'cgidir'} );

## Read snmp.ini

open( FL, &convertdir( $inivar{'slash'}, $inivar{'httpdir'}, "conf", $snmpini ));
@test = <FL>;
close( FL );

$inivar{seperatorheight} = 0;
$inivar{topheight} = 91;
$inivar{menuwidth} = 100;

foreach $i (0..$#test)
{
$key = substr( $test[$i], 0, index( $test[$i], "=" ) );
$key =~ tr/ \n\r//d;
$value = substr( $test[$i], 1 + index( $test[$i], "=" ) );
$value =~ tr/\n\r//d;
$n = 0;
while( index( $value, ' ' ) == 0 && $n < 100 )
{
$value = substr( $value, 1 );
$n++;
}
$inivar{$key} = $value;
}
}

sub convertdir (@) {
my($slash, @items) = @_;
my($i,$str);

$str = "";
foreach $i (0..$#items)
{
$items[$i] =~ tr/\n\r//d;
$items[$i] =~ tr/\\/\//;
$str .= "/";
$str .= $items[$i];
}
@items = ();
@items = split( "/", $str );
$str = "";
foreach $i (0..$#items)
{
if( index( $items[$i], ':' ) > 0 )
{
$items[$i] = "";
}
if( length($items[$i]) > 0 )
{
$str .= $slash;
$str .= $items[$i];
}
}
$str =~ tr/\n\r//d;
return $str;
}

sub mainframework (@) {
my($snmpini) = @_;
my( $str, $cgidir, $pmenu, $menu, $top, $sep );

$cgidir = $inivar{'cgidir'};
$pnino = "nino.pl";

$sep = $inivar{'seperatorheight'};
$top = $inivar{'topheight'};
$menu = $inivar{'menuwidth'};

$str = "Content-type: text/html\n\n";
$str .= "<HTML><TITLE>Network Manager</TITLE>\n";

if( $top > 0 )
{
if( $sep > 0 )
{
$str .= "<FRAMESET FRAMEBORDER=0 FRAMEBORDER=NO BORDER=0 FRAMESPACING=0 ROWS=$top,$sep,*>\n";
# $str .= "<FRAMESET FRAMEBORDER=0 FRAMEBORDER=NO BORDER=0 FRAMESPACING=0 ROWS=88,40,*>\n";

$str .= "<FRAMESET FRAMEBORDER=0 FRAMEBORDER=NO BORDER=0 FRAMESPACING=0 COLS=$menu,*>\n";
$str .= "<FRAME MARGINWIDTH=0 FRAMEBORDER=0 FRAMEBORDER=NO BORDER=0 FRAMESPACING=0 SRC=/$cgidir/$pnino?action=drawmenu&menu=top&snmpini=$snmpini NAME=left SCROLLING=no>\n";
$str .= "<FRAME MARGINWIDTH=0 NAME=viewer SRC=/$cgidir/$pnino?action=blank&snmpini=$snmpini>\n";
$str .= "</FRAMESET>\n";

$str .= "<FRAMESET FRAMEBORDER=0 FRAMEBORDER=NO BORDER=0 FRAMESPACING=0 COLS=1800,*>\n";
$str .= "<FRAME MARGINWIDTH=0 FRAMEBORDER=0 FRAMEBORDER=NO BORDER=0 FRAMESPACING=0 SRC=/$cgidir/$pnino?action=drawmenusep&snmpini=$snmpini NAME=middle SCROLLING=no>\n";
$str .= "<FRAME MARGINWIDTH=0 NAME=mid SRC=/$cgidir/$pnino?action=blank&snmpini=$snmpini>\n";
$str .= "</FRAMESET>\n";

$str .= "<FRAMESET FRAMEBORDER=0 FRAMEBORDER=NO BORDER=0 FRAMESPACING=0 COLS=$menu,*>\n";
$str .= "<FRAME MARGINWIDTH=0 FRAMEBORDER=0 FRAMEBORDER=NO BORDER=0 FRAMESPACING=0 SRC=/$cgidir/$pnino?action=drawmenu&menu=bottom&snmpini=$snmpini NAME=left SCROLLING=no>\n";
$str .= "<FRAME MARGINWIDTH=0 NAME=bottom SRC=/$cgidir/$pnino?action=blank&snmpini=$snmpini>\n";
$str .= "</FRAMESET>\n";

$str .= "</FRAMESET>\n";

$str .= "</HTML>\n";
}
else
{
$str .= "<FRAMESET FRAMEBORDER=0 FRAMEBORDER=NO BORDER=0 FRAMESPACING=0 ROWS=$top,*>\n";

$str .= "<FRAMESET FRAMEBORDER=0 FRAMEBORDER=NO BORDER=0 FRAMESPACING=0 COLS=$menu,*>\n";
$str .= "<FRAME MARGINWIDTH=0 FRAMEBORDER=0 FRAMEBORDER=NO BORDER=0 FRAMESPACING=0 SRC=/$cgidir/$pnino?action=drawmenu&menu=top&snmpini=$snmpini NAME=left SCROLLING=no>\n";
$str .= "<FRAME MARGINWIDTH=0 NAME=viewer SRC=/$cgidir/$pnino?action=blank&snmpini=$snmpini>\n";
$str .= "</FRAMESET>\n";

$str .= "<FRAMESET FRAMEBORDER=0 FRAMEBORDER=NO BORDER=0 FRAMESPACING=0 COLS=$menu,*>\n";
$str .= "<FRAME MARGINWIDTH=0 FRAMEBORDER=0 FRAMEBORDER=NO BORDER=0 FRAMESPACING=0 SRC=/$cgidir/$pnino?action=drawmenu&menu=bottom&snmpini=$snmpini NAME=left SCROLLING=no>\n";
$str .= "<FRAME MARGINWIDTH=0 NAME=bottom SRC=/$cgidir/$pnino?action=blank&snmpini=$snmpini>\n";
$str .= "</FRAMESET>\n";

$str .= "</FRAMESET>\n";

$str .= "</HTML>\n";
}
}
else
{
if( $sep > 0 )
{
$str .= "<FRAMESET FRAMEBORDER=0 FRAMEBORDER=NO BORDER=0 FRAMESPACING=0 ROWS=$sep,*>\n";

$str .= "<FRAMESET FRAMEBORDER=0 FRAMEBORDER=NO BORDER=0 FRAMESPACING=0 COLS=1800,*>\n";
$str .= "<FRAME MARGINWIDTH=0 FRAMEBORDER=0 FRAMEBORDER=NO BORDER=0 FRAMESPACING=0 SRC=/$cgidir/$pnino?action=drawmenusep&snmpini=$snmpini NAME=middle SCROLLING=no>\n";
$str .= "<FRAME MARGINWIDTH=0 NAME=mid SRC=/$cgidir/$pnino?action=blank&snmpini=$snmpini>\n";
$str .= "</FRAMESET>\n";

$str .= "<FRAMESET FRAMEBORDER=0 FRAMEBORDER=NO BORDER=0 FRAMESPACING=0 COLS=$menu,*>\n";
$str .= "<FRAME MARGINWIDTH=0 FRAMEBORDER=0 FRAMEBORDER=NO BORDER=0 FRAMESPACING=0 SRC=/$cgidir/$pnino?action=drawmenu&menu=bottom&snmpini=$snmpini NAME=left SCROLLING=no>\n";
$str .= "<FRAME MARGINWIDTH=0 NAME=bottom SRC=/$cgidir/$pnino?action=blank&snmpini=$snmpini>\n";
$str .= "</FRAMESET>\n";

$str .= "</FRAMESET>\n";

$str .= "</HTML>\n";
}
else
{
$str .= "<FRAMESET FRAMEBORDER=0 FRAMEBORDER=NO BORDER=0 FRAMESPACING=0 ROWS=$top,*>\n";

$str .= "<FRAMESET FRAMEBORDER=0 FRAMEBORDER=NO BORDER=0 FRAMESPACING=0 COLS=$menu,*>\n";
$str .= "<FRAME MARGINWIDTH=0 FRAMEBORDER=0 FRAMEBORDER=NO BORDER=0 FRAMESPACING=0 SRC=/$cgidir/$pnino?action=drawmenu&menu=bottom&snmpini=$snmpini NAME=left SCROLLING=no>\n";
$str .= "<FRAME MARGINWIDTH=0 NAME=bottom SRC=/$cgidir/$pnino?action=blank&snmpini=$snmpini>\n";
$str .= "</FRAMESET>\n";

$str .= "</FRAMESET>\n";

$str .= "</HTML>\n";
}
}
print $str;
}
[/quote]

更新: 程序我放到 quote 里,下次注意 -- qiang




   

狮子大张口~ [C...
狮子大张口~ [CCB]4[/CCB]
[color=red]这是用Perl写的CGI,解释完毕![/color]
maininit func...
maininit function 好像处理分析了一些 %ENV http 参数 和 snmp.ini 文件。
mainframework 只是生成 frame 页面。
没看出你这个程序有什么用途。

另, 问问题时不要扔给大家一个程序,请讲明白哪里看不懂 ,或者提出你的疑问。
[quote]回复给 ...
[quote]回复给 qiang : maininit func......[/quote]

他老兄希望你都给注释一遍...