in reply to Re^2: using Getopt::Long to modify the default values in new
in thread using Getopt::Long to modify the default values in new

#$self{$property} = delete $param_hr->{$property};

The way I read the delete function in perldoc.perl.org listing for delete, the RHS populates the left.

From delete:

In list context, usually returns the value or values deleted, or the last such element in scalar context. The return list's length corresponds to that of the argument list: deleting non-existent elements returns the undefined value in their corresponding positions.

Perhaps it's not a good idea to delete the keys you set in $self from your input parameters. A simple $self{$property} = $param_hr->{$property}; suffices. You realise that by deleting, you modify a data structure created by the caller (%param_hr).

The Use of uninitialized value $akey in concatenation (.) or string at ./6.MY.translate.pl line 62. can be avoided if you move say "akey is  $akey "; after you check it is defined

Validating your input is great. But personally I would not validate the data types of params passed in a module's constructor. When you have a script and users run it from command line it is wise to (edit:over-)validate because a user may not have read the manual or is confused about input parameters. This is the normal scenario - judging from how I make such mistakes. However, I would categorise the programmer/user/caller of an API/module in slightly higher level and I would trust this user more. So I would still validate input params for right input values but checking for type, well that may cause me and the CPU too much extra work and just I do not do it. Practical reason: I sometimes set default params in $self to be undef. In which case no data type can be deduced. Saying in the pod that "this module does not validate input types, please observe the parameters' types stated" is enough for me. But may not be for others.

Note that if ( exists $param_hr->{$property} ) { passes if key exists, but its value may be undefined. e.g. for this input: $param_hr{'key'} = undef; edit: clearly 'key' exists, so exists passes, but its value is undef which !perhaps! misses what author intended.