There are two kinds of errors: supplying an unrecognized parameter, or failing to supply a recognized parameter. You'll have to worry about the second issue as you edit the list of parameters and make sure that the new parameters are used consistently throughout the application.
The best and easiest solution is to use another hash.
my @params = qw(commandType commandId channel1Enabled ...);
my %copy = %params;
my @validation_errors = ();
# are all the required parameters present?
foreach my $param (@params) {
if (not exists $copy{$param}) {
push @validation_errors, "Required param '$param' is missing.";
}
delete $copy{$param};
}
# since we have delete'd all the recognized parameters,
# anything left is unrecognized
foreach my $param (keys %copy) {
push @validation_errors, "Unrecognized param '$param' = '$copy{$param}' in input.";
}
if (@validation_errors) {
die "errors in input:\n", join("\n", @validation_errors);
}