in reply to Re^3: How best to validate the keys of hashref arguments?
in thread How best to validate the keys of hashref arguments?
Like this perhaps ?
poj#!perl use strict; use Hash::Util 'lock_keys'; use Data::Dumper ; # valid my $cmd = ops_new_cmd({ name=>1, user=>2, host=>3}); print Dumper $cmd; # not valid $cmd = ops_new_cmd({ name=>1, user=>2, hostt=>3}); sub ops_new_cmd { my ($init_hash) = @_; my @valid = qw( name user host key command status ssh_retcode ssh_retmsg output std_err cmd_ret_code cmd_ret_msg); + lock_keys(my %new_cmd,@valid); %new_cmd = %$init_hash; return \%new_cmd; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: How best to validate the keys of hashref arguments?
by cbeckley (Curate) on Mar 16, 2017 at 19:36 UTC |