in reply to php style includes
It may look very different, and you can get away with tieing the hash to do lazy lookups. The important point is that, if you have a persistent process that may need to read several files, open them only when necessary and store them all other times.my %templates; # some code sub include { my $tpl = shift; $templates{$tpl} ||= fetch($tpl); return $tpl; } sub fetch { my $tpl = shift; local (*TPL, $/); open(TPL, "template_folder/$tpl") or return; return <TPL>; }
If your process isn't persistent, then there's not a lot you can do. Open them only when you need to, and pray to the virtual memory subsystem that they stay in cache.
|
|---|