#!/usr/bin/perl use strict; use warnings; use Test::More 'no_plan'; ######################### # Three variables used as constants in the following my $rfoo = 10; my @rbar = qw( ciao a tutti ); my %rbaz = ( first => 'aaaa', second => ['bbbb'], third => { yes => 'and so on'} ); # Declare three persistent variables. The mechanism is the # same as use vars. use vars::persistent qw( $foo @bar %baz ); # Initialise to the constant values above $foo = $rfoo; @bar = @rbar; %baz = %rbaz; # Silly verification here is($foo, $rfoo, "scalar value"); is_deeply(\@bar, \@rbar, "array"); is_deeply(\%baz, \%rbaz, "hash"); # Checkpoint, i.e. save to file vars::persistent::checkpoint('savefile'); # Reset values $foo = 0; @bar = (); %baz = (); # Restore from file vars::persistent::restore(); # file name is cached # These tests are the real one now is($foo, $rfoo, "scalar value"); is_deeply(\@bar, \@rbar, "array"); is_deeply(\%baz, \%rbaz, "hash");