c:\@Work\Perl\monks>perl -le "use warnings; use strict; ;; use Test::More 'no_plan'; use Test::NoWarnings; ;; use constant TEST_SET => ( 'undefined default values', [ { one => 1, three => 3, two => 2 }, 'one 1 two 2 three 3', ], [ { odd => undef, one => 1, three => 3, two => 2 }, 'one 1 two 2 three 3 odd', ], [ { odd => undef, one => 1, three => 3, two => 2 }, 'one 1 two 2 odd three 3', ], [ { odd => undef, one => 1, three => 3, two => 2 }, 'odd one 1 two 2 three 3', ], 'defined default values', [ { one => 1, three => 3, two => 2 }, 'one 1 two 2 three 3', 'xxx', ], [ { odd => 'xxx', one => 1, three => 3, two => 2 }, 'one 1 two 2 three 3 odd', 'xxx', ], [ { odd => 'xxx', one => 1, three => 3, two => 2 }, 'one 1 two 2 odd three 3', 'xxx', ], [ { odd => 'xxx', one => 1, three => 3, two => 2 }, 'odd one 1 two 2 three 3', 'xxx', ], ); ;; VECTOR: for my $ar_vector (TEST_SET) { if (not ref $ar_vector) { note $ar_vector; next VECTOR; } ;; my ($expected_hashref, $string, $default) = @$ar_vector; ;; is_deeply { odd_hash($string, $default) }, $expected_hashref; } ;; done_testing; ;; ;; sub odd_hash { my ($string, $default) = @_; ;; my %hash = map defined() ? $_ : $default, $string =~ m{ ([^\W\d]+) (?: \s* (\d+))? }xmsg ; return %hash; } " # undefined default values ok 1 ok 2 ok 3 ok 4 # defined default values ok 5 ok 6 ok 7 ok 8 1..8 ok 9 - no warnings 1..9