sub get_defaults { return +{ output_type => 'excel', output_dir => '/tmp', ... }; }; #### use YAML 'LoadFile'; sub config_from_file { my( $filename ) = @_; LoadFile( $filename ) } #### sub config_from_ENV { my ( $env ) = @_; { output_type => $env->{MYAPP_output_type}, ... } } #### sub config_from_ARGV { my( $argv ) = @_; GetOptionsFromArray ( 'f|config_file:s' => \my $config_file, 't|output_type:s' => \my $output_type, ); return +{ config_file => $config_file, output_type => $output_type, }, #### my $defaults = get_defaults(); my $argv = config_from_ARGV( \@ARGV ); my $config_file = $argv->{config_file} || 'myconfig.yml'; my $file = config_from_file( $config_file ); my $env = config_from_ENV( \%ENV ); # Merge the things my $final_config = $defaults; for my $cfg ($config_file, $env, $argv) { for my $entry (keys %$cfg) { if(defined $cfg->{$entry}) { $final_config->{ $entry } = $cfg->{ $entry }; }; }; };