Hi,
I have a problem with creating a hash which has a a variable in its name. This works ok for arrays ,eg
@{"platforms_$site"}
but not hashes
%{"platforms_$site"}
Here's my script:
#!/usr/bin/perl
sub buildconfig;
buildconfig;
foreach $key(keys %sites){
print "$key\n";
}
sub buildconfig{
my ($site, $platform, $webserver, $option);
my %sites = map {$_=>1} @sites;
# create following variables
# %sites = BFH, LPR, UAT, TEST
# @all_platforms and %all_platforms = TEST_MLS, TEST_RST, UAT_
+MLS, UAT_RST ...
# %platform_TEST = TEST_MLS, TEST_RST, TEST_OPP, TEST_BO ...
# @all_webservers and %all_webservers = mls001.test, mls002.te
+st, tomcat001.test, tomcat002.test ...
# %webservers_TEST_MLS = mls001.test, mls002.test
# %deploy_as = prod, standby, demo
# %deploy_as_platforms = Prod1, Prod2, UAT, TEST
my %sites = map {$_=>1} @sites;
foreach $site (@sites) {
my %all_platforms = map {$_=>1} @{"platforms_$site"};
my %{"platforms_$site"} = map {$_=>1} @{"platforms_$si
+te"};
foreach $platform (keys %{platforms_$site}) {
my %all_webservers = map {$_=>1} @{"webservers
+_$platform"};
my %{"webservers_$platform"} = map {$_=>1} @{"
+webservers_$platform"};
}
}
my @all_platforms=sort keys(%all_platforms);
my @all_webservers=sort keys(%all_webservers);
my %deploy_as = map {$_=>1} @deploy_as;
my %deploy_as_platforms = map {$_=>1} @deploy_as_platforms;
}
but when it's run I get:
Can't declare hash dereference in my at ./test.pl line 30, near "} ="
Execution of ./test.pl aborted due to compilation errors.
Could anyone tell me how to fix that please?
Thanks,
Ed.