in reply to Persistence.pm

A simple test case repeats what I see in my code:
#!/usr/local/bin/perl -w # # name: persistest # # does stuff # works fine use vars qw( %hash ); use strict; use Persistence 'test.dat'; my ($k, $v, $n); foreach (($k, $v) = each %hash) { $n++; print "$n: $k => $v\n"; } %hash = ( blue => 'berries', red => 'roses', black => 'coffee', yellow => 'bananas', ); END { persistent '%hash'; }
produces
$ ./persistest 1: => 2: =>
Warnings removed to improve readability. Why it iterates twice when it can't find the values, I can't figure.

perl -e 'print qq(Just another Perl Hacker\n)' # where's the irony switch?

janitored by ybiC: Append "for Persistance.pm" to title for better site search results

Replies are listed 'Best First'.
Ea answers own question!
by Ea (Chaplain) on Mar 30, 2005 at 12:55 UTC
    Need to use it with a call for the persistant variable to invoke the stored values. So test case works fine with
    #!/usr/local/bin/perl -w # # name: persistest # # does stuff # works fine use vars qw( %hash ); use strict; use Persistence 'test.dat';
    persistent '%hash';
    my ($k, $v, $n);
    while
    (($k, $v) = each %hash) { $n++; print "$n: $k => $v\n"; } %hash = ( blue => 'berries', red => 'roses', black => 'coffee', yellow => 'bananas', ); END { persistent '%hash'; }
    The loop funniness was due to using foreach instead of while over the calls to each %hash.

    Nothing to see here. Move along.

    perl -e 'print qq(Just another Perl Hacker\n)' # where's the irony switch?
      Just a quick observation: generally speaking when answering your own question, the convention is to post an Update: on the original node, so that readers don't need to read the entire thread to find out the problem is solved.

      Update: Just checked your homenode and found out you've been here on the monastery a lot longer than me! Still, I had to read the whole thread before finding out it was solved, so I guess it was worth the reminder.

      Update: OP now posted update on original post.

      g0n, backpropagated monk