Hi, you can use a state variable : before sub { state $cache_loaded ||= _load_cache(); } the only requirements are that you use perl 5.10 or greater, and that _load_cache() does all the init you want, and return true on success. On 20 May 2011 20:57, Nick Knutov <mail@knutov.com> wrote:
Hello all,
what is the best way to do some initialization for some data on the only first run? Something like 'before sub', but it should run only on the first run of the script instance.
Example of use:
our $first; before sub { # if this is the first run of instance # $cache->{statuses} = ... # load some static data from DB
# I can do # _load_cache() unless $first; # $first = 1; # but this is not beautiful }
-- Best Regards, Nick Knutov http://knutov.com ICQ: 272873706 Voice: +7-904-84-23-130 _______________________________________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users