in reply to Effecient shortcut for ?:

Another approach to the ones above is to establish defaults when you set up the hash. This is common when creating objects.
sub new { my $pkg = shift; my $self = { a => $default_for_a, @_ }; bless $self, $pkg; }
If you don't specify a binding for "a" when you create the instance, you get the default. If do specify a binding, as with   my $foo = new Foo(a => 47); then the default is overlaid.

Replies are listed 'Best First'.
Re^2: Effecient shortcut for ?:
by tadman (Prior) on Aug 07, 2002 at 18:49 UTC
    I do this occasionally, when establishing quick defaults. Testing revealed that the last defined key/value pair for a given hash is the one that is used. Is this documented anywhere?
    my $self = { %defaults, @_ };
      As far as I know, it's only documented in the same sense as this bit of code:
      my $x; $x = 1; $x = 2;