Just put %hash inside bless {} directly ...
$self = bless { 'intpref' => $intpref, 'prefix' => $prefix, 'telnum' => $telnum, 'smstext' => $smstext, 'cookie_jar' => "lwpcookies.txt", %hash, }, $class;
... which has the added benefit of making defaults real easy, because the user can just insert a key/value pair for whatever they want to override (ie, 'cookie_jar' in the above: if it exists in %hash, the new value will replace the default), saving you of going through the motions of 'key' => exists $hash{'key'} ? delete $hash{'key'} : 'my default',.
And since you don't use %hash anywhere else, you could feasibly rid yourself of temporary assignments by reducing the above to...
sub new { my $class = shift; my $self = bless { 'intpref' => shift, 'prefix' => shift, 'telnum' => shift, 'smstext' => shift, 'cookie_jar' => "lwpcookies.txt", @_, }, $class; # ... other things with $self ... $self; }
--k.
In reply to Re: Optional parameters in new() method
by Kanji
in thread Optional parameters in new() method
by giulienk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |