A slightly different approach is to define a default for every argument and explicitly make any required argument undefined. Then check for undefined arguments, take action as appropriate. This can generate a lot of useful warnings.

>perl -wMstrict -le "print send_values({name => 'Joe Doe', addr => '123 4th St.'}); print send_values({ addr => '666 Mobil Ave.', phone => '321-432-5432' }); print send_values({ name => 'Moe Foe', addr => '7 6th Rd.', phone => '432-543-6543' }); ;; sub send_values { my ($hr_args) = @_; ;; my %defaults = ( name => undef, addr => undef, phone => '(not given)', ); ;; my %args = (%defaults, %$hr_args); my @bad = grep !defined($args{$_}), keys %args; return undef if @bad and warn((caller 0)[3], qq{: bad arg(s): @bad}); ;; return sprintf qq{<n>%s</n> <a>%s</a> <p>%s</p>}, @args{ qw(name addr phone) }; } " <n>Joe Doe</n> <a>123 4th St.</a> <p>(not given)</p> main::send_values: bad arg(s): name at -e line 1. Use of uninitialized value in print at -e line 1. <n>Moe Foe</n> <a>7 6th Rd.</a> <p>432-543-6543</p>

In reply to Re: Subroutine question on use of uninitialized value. by AnomalousMonk
in thread Subroutine question on use of uninitialized value. by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":