我难以理解这个代码应该如何工作。我已经在while循环之外定义了两个哈希表,并且目标是能够检测shell类型,并将相应的哈希表赋值给新的$shell变量。以下是我目前正在尝试的代码:
#!/usr/bin/perl
use strict;
use warnings;
use POSIX;
use DateTime;
use Term::ANSIColor qw(:constants);
local $Term::ANSIColor::AUTORESET = 1;
my $dt = DateTime->now; # Stores current date and time as datetime object
my %multicity = (
url => "example.com",
ftpuser => "user",
ftppass => "pass",
remote_dir => "/httpdocs/",
dbname => "database"
);
my %singlecity = (
url => "example2.com",
ftpuser => "user",
ftppass => "pass",
remote_dir => "/httpdocs/",
dbname => "database"
);
open (MYFILE, 'sites.txt');
LINE: while (<MYFILE>) {
next LINE if /^#/;
my ($shelltype, $siteurl, $ftpuser, $ftppass, $dbname) = split /\|/;
# 1|example.com|user|pass|databasename - This should be a singlecity shell type.
if ($shelltype == 1) { my $shell = \%multicity; } else { my $shell = \%singlecity; };
print "Shelltype: $shelltype\n";
print "Should be $shell{url}\n";
}
close (MYFILE);
我已经尝试了许多不同的方法,但都没有用,所以最终决定向stackoverflow上的专家求助,以获取一些方向!
非常感谢任何帮助。谢谢。