equick has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
I have a problem with creating a hash which has a a variable in its name. This works ok for arrays ,eg
but not hashes@{"platforms_$site"}
Here's my script:%{"platforms_$site"}
but when it's run I get:#!/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; }
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: syntax for hashes with variable in name
by jethro (Monsignor) on Nov 22, 2010 at 12:47 UTC | |
by ikegami (Patriarch) on Nov 22, 2010 at 17:18 UTC | |
by ambrus (Abbot) on Nov 22, 2010 at 13:55 UTC | |
by Tux (Canon) on Nov 22, 2010 at 16:46 UTC | |
by jethro (Monsignor) on Nov 22, 2010 at 16:02 UTC | |
by equick (Acolyte) on Nov 22, 2010 at 13:06 UTC | |
|
Re: syntax for hashes with variable in name
by Tux (Canon) on Nov 22, 2010 at 15:39 UTC | |
by aquarium (Curate) on Nov 23, 2010 at 02:44 UTC |