DBX has asked for the wisdom of the Perl Monks concerning the following question:
With a constructor that doesn't account for no arguments being sent in. I usually use the following:my $obj = Class->new();
The line: $data ||= {}; always seems hackish to me. Is there a better way?sub new{ my ($class,$data) = @_; $data ||= {}; ## avoid empty hashref errors my $attr = { %$data, }; bless $attr, $class; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Avoiding empty HASH ref. errors
by synapse0 (Pilgrim) on Jul 16, 2001 at 10:32 UTC | |
|
Re: Avoiding empty HASH ref. errors
by ariels (Curate) on Jul 16, 2001 at 11:34 UTC | |
|
Re: Avoiding empty HASH ref. errors
by nysus (Parson) on Jul 16, 2001 at 13:14 UTC |