in reply to Re: How best to validate the keys of hashref arguments?
in thread How best to validate the keys of hashref arguments?
Wow, haukex, thank you. There's a lot of info in there. Restricted hashes from Hash::Util works beautifully and is exactly what I was looking for.
For the curious, I added a sub to my ssh module:
sub ops_new_cmd { my ($init_hash) = @_; my $new_cmd = {}; lock_ref_keys($new_cmd, qw(name user host key command status ssh_re +tcode ssh_retmsg output std_err cmd_ret_code cmd_ret_msg)); for my $k (keys %$init_hash) { $new_cmd->{$k} = $init_hash->{$k}; } return $new_cmd }
And then invoking it, from my initial example:
my @commands = ( ops_new_cmd({ name => 'command_name1', user => 'user1', host => 'server1.foo.com', command => 'rsync_command yadda yadda' }), ops_new_cmd({ name => 'command_name2', user => 'user2', host => 'server2.foo.com', command => 'rsync_command yadda yadda' }) );
You are correct, however, I am going to need to add some validation to the values at some point. I'm leaning toward using OO. Thank you for the examples there as well.
Thanks,
cbeckley
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: How best to validate the keys of hashref arguments?
by cbeckley (Curate) on Mar 16, 2017 at 17:48 UTC | |
by haukex (Archbishop) on Mar 16, 2017 at 19:15 UTC | |
by cbeckley (Curate) on Mar 16, 2017 at 19:53 UTC | |
by poj (Abbot) on Mar 16, 2017 at 19:03 UTC | |
by cbeckley (Curate) on Mar 16, 2017 at 19:36 UTC |