The code, saved as script.pl:<config> <profile name="Test"> <dat_file_location>e:\</dat_file_location> <logdir>Test</logdir> <drop_script>n_a</drop_script> <database_type>MSSQL</database_type> <scripts_sql_dlt>blah</scripts_sql_dlt> <TNS-DSN_name>SwissTest</TNS-DSN_name> <db_user>db_builder</db_user> <password>pass</password> <log_file>Test.log</log_file> <single_sql_file>create_db.sql</single_sql_file> <single_dlt_file>blah</single_dlt_file> </profile> <profile name="Live"> <dat_file_location>e:\</dat_file_location> <logdir>Live</logdir> <drop_script>n_a</drop_script> <database_type>MSSQL</database_type> <scripts_sql_dlt>blah</scripts_sql_dlt> <TNS-DSN_name>Live</TNS-DSN_name> <db_user>db_builder</db_user> <password>pass</password> <log_file>Live.log</log_file> <single_sql_file>create_db.sql</single_sql_file> <single_dlt_file>blah</single_dlt_file> </profile> </config>
And calling it as "script.pl Test" I am not able to get it to work...# Load XML Config file... use XML::Simple; my $config = XMLin(); # Find the right config... # This should be the only commandline argument my $desired_config = $ARGV[0]; # Dump the config file.... use Data::Dumper; print Dumper($config); print $config->{$desired_config}->{database_type};
I need to be able to specify the config from the command line...print $config->{profile}->{$desired_config}->{database_type}; print "\nTest1\n"; print $config->{profile}->{config}=>$desired_config->{database_type}; print "\nTest2\n"; print $config->{profile}->{config => $desired_config}->{database_type} +; print "\nTest3\n"; # Below is the only one that works.... # It is hardcoded... print $config->{profile}->{Test}->{database_type}; print "\nTest4\n"; print $config->{$desired_config}->{database_type}; print "\nTest5\n"; print $config->{profile}->{$desired_config}->{database_type}; print "\nTest6\n"; print $config->{profile}=>{$desired_config}->{database_type}; print "\nTest7\n";
In reply to XML::Simple and variable interpolation by amonotod
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |