lesage has asked for the wisdom of the Perl Monks concerning the following question:
And this is what happens, when the program calls set_enginepackage 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; }
(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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Perl Riddle
by shmem (Chancellor) on Dec 01, 2007 at 12:26 UTC | |
Re: Perl Riddle
by Zaxo (Archbishop) on Dec 01, 2007 at 09:45 UTC | |
Re: Perl Riddle
by Somni (Friar) on Dec 01, 2007 at 10:35 UTC | |
Re: Perl Riddle
by Prof Vince (Friar) on Dec 01, 2007 at 10:41 UTC | |
Re: Perl Riddle
by webfiend (Vicar) on Dec 03, 2007 at 22:08 UTC |