Our holyness divined a riddle to me, which I am unworthy to understand. Perhaps the higher clergy can guide my way.
package Data::CryptRecord; BEGIN { use strict; [ ... ] our %ENGINES; } sub register { ... } # adds to the %ENGINES hash # List what's in the hash sub list_engines { my $self = shift; my @eng; while( my ($k, $v) = each(%ENGINES)){ push @eng, $v->{'name'}; } return @eng; } # Chose a distinct crypt method for this instance # Lot's of list_engines included for debugging sub set_engine { my ($self, $name) = @_; $name = uc($name); print "Enter set_engine (" . scalar $self->list_engines . ")\n"; while( my ($k, $v) = each(%ENGINES)){ next unless(uc($v->{'name'}) eq $name); $self->{'enc_type'} = $k; print "Exit OK set_engine (" . scalar $self->list_engines . ") +\n"; return 0; } print "Exit fail set_engine (" . scalar $self->list_engines . ")\n +"; return -1; }
And this is what happens, when the program calls set_engine
(not shown, at the end of the CTOR) Blessed List(1) Enter set_engine(1) Exit OK set_engine (0) after set_list (1) (This is another list_engines called later in the program)

So sometimes %ENGINES appears to be empty, but it recovers magically. Does anyone have an idea, where to start the search?

BTW: The program has a ncurses UI, therefore perl -d is tedious. Is there a way to redirect the debugging console to a different VT or XTerm?

Humbly praying for revelations ...
- lesage

Thanks a lot for your help. The crucial issue was resetting the each() iterator. So special thanks to ProfVince and shmem.

Still, use warnings; and clarification that BEGIN{} is in no way a special scope, were also very helpful.

I meanwhile figured out that

export PERLDB_OPTS='TTY=/dev/pts/2' perl -d ./myprg.pl

can be used to redirect the perl debugger console. Tying e.g. a picocom on its own pty does almost what I'd like to have -- apart from local echo and CR/LF conversion. I'd bet there is a Perl program around doing such things. Does anybody have a pointer?

- lesage


In reply to Perl Riddle by lesage

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.