截至目前我有一台新电脑,我还在安装perl我需要一个来测试我的程序输出是什么(如果它甚至可以工作)如果不是请告诉我我能做些什么来解决它(Config :: INI :: Reader是一个cpan类,所以你可能想要它,如果你没有它
perl代码:
#!/usr/bin/perl
use warnings;
use strict;
use IO::Socket;
use Config::INI::Reader;
my $file = "ServerSettings.ini";
my $ini = Config::INI::Reader->read_file($file);
my $server_info = $ini->{'ServerInfo'};
my $version = $ini->{'Version'};
my $host = $server_info->{'address'};
my $port = $server_info->{port};
my $server = new IO::Socket::INET(Proto=>'tcp',PeerAddr=>$host,PeerPort=>$port);
die "Connection Failed \n" unless $server;
print "Connection Established \n";
print "James Server" . $version->{ver} . "\n";
print "Hello From James Server";
这是ini:
[ServerSettings]
port=1234
address"localhost"
[Version]
ver="1.0.3"
答案 0 :(得分:1)
#!/usr/bin/perl -l
use warnings;
use strict;
use Config::INI::Reader;
my $file = "/tmp/l.ini";
my $ini = Config::INI::Reader->read_file($file);
my $server_info = $ini->{ServerSettings};
my $version = $ini->{Version};
my $host = $server_info->{address};
my $port = $server_info->{port};
my $ver = $version->{ver};
print $host;
print $port;
print $ver;
ini文件中有拼写错误,缺少=
[ServerSettings]
port=1234
address="localhost"
[Version]
ver="1.0.3"