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
In reply to Re^2: How best to validate the keys of hashref arguments?
by cbeckley
in thread How best to validate the keys of hashref arguments?
by cbeckley
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |