On Mon, 30 Nov 2009 14:36:44 +0000, Dermot wrote:
> sub get_cached_val_or_lookup {
>     my $val = shift;
>     return $cache{$val} ||= do {

Could be more effective in 5.10 with

  return $cache{$val} //= do {

to avoid repeating the fetch for values that are false.

> One more question If I can. Chas pointed me to
> http://perldesignpatterns.com/?PerlDesignPatterns some time ago. I
> suspect that the above is a form of design pattern. Does it have a name?

It's called the Orcish Maneuver ("or-cache").  See: "Effective Perl 
Programming", Hall with Schwartz.

> Is there a reference to it at
> http://perldesignpatterns.com/?PerlDesignPatterns

It's not really a design pattern, those are about higher levels of 
abstraction to do with objects.  Usually.  It's an idiom.

-- 
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to