use strict; use warnings; use Test::More tests=>2; my $raw_path = '$HOME/work_dir/${TOOL_NAME}/$VERSION'; my $required_path = 'home/work_dir/hammer/1.01'; my %env = ( # Dummy hash for testing HOME => 'home', TOOL_NAME => 'hammer', #VERSION => '1.01', # Removed to force error ); sub resolve_env_in_path { my ($path) = @_; while ($path =~ m/\$\{?(\w+)\}?/) { my $field; if( exists($env{$1}) ) { $field = $env{$1}; } else { warn "Invallid path"; $field = 'UNSPECIFIED'; } $path =~ s/\$\{?(\w+)\}?/$field/; } return $path; }; ok( resolve_env_in_path($raw_path) ne $required_path, 'error expected' ); $env{VERSION} = '1.01'; ok( resolve_env_in_path($raw_path) eq $required_path, 'good' );