in reply to More efficient ways to pass values to a sub routine

Here is a way to initialize defaults if a key/value are not passed to the sub. Forget where I saw this technique, possibly here.

use Data::Dumper; sub send_2 { my %args = (name => 'default', filehandle => 'default', id => 'default', %{ +shift } ); print Dumper \%args; } send_2( {name => 'Tom', id => 'IT001'} ); send_2( {name => 'Mary', filehandle => 'ARGV', id => 'foo'} );
Output is:
$VAR1 = { 'filehandle' => 'default', 'name' => 'Tom', 'id' => 'IT001' }; $VAR1 = { 'filehandle' => 'ARGV', 'name' => 'Mary', 'id' => 'foo' };
The sub assigns a default value (here 'default') which is overwritten if a value is passed to the sub when called.

(You could have just as easily have a default == the empty string ('') or whatever you want as a default.