# warning, pseudocode
foo(4); # prints "4"
foo(); # prints "4"
sub foo {
static int bar;
bar = shift() unless defined bar;
print bar;
}
####
sub too_slow {
my $object = ReallyHuge::SlowObject -> new(%args);
# do stuff with $object
return "stuff";
}
##
##
sub less_slow {
my $object;
$object = $dbh -> @{selectall_arrayref("select object from storage")}[0];
if ($object -> exists()) {
# behave normally
}
else {
$object = ReallyHuge::SlowObject -> new(%args);
$dbh -> do("update storage set object='$object'");
}
}