A mock up of dispatch table. No dispatching done here... only a test of passing values.
What am running into here? one sub function called (dispt('hello',@ar); ) containing a dispatch table. A third sub function is called in the dispatch table ( N(@_); ) but the variables don't survive to be use there. The output from the script below: Shows 6 elements arrive in dispt($g, @ar) as @_. But when sub N(@_) is called, no variables arrive there. @_ is empty. When it seems like 5 elements should have arrived there hpdb @_<6> press N to test this dispatch table press c to continue (no action taken) press q to Exit (abort completely) N hpdb @_<0> press N to test this dispatch table press c to continue (no action taken) press q to Exit (abort completely) q Goodbye ------- --------- ---=--- --------- -------- #!/usr/local/bin/perl use strict; use warnings; my $debug = 1; my @ar = ("one","two","three","four","five"); my $g ='hello '; dispt($g,@ar); sub dispt { my $cnt = 1; $debug and print "hpdb \...@_<"....@_. ">\n"; my %dispt = ( N => sub { print N(@_). "\n"; }, c => sub { print "Continue\n"; $cnt = 0; }, q => sub { print "Goodbye\n" and exit; }, error => sub { print "invalid selection\n" } ); while ($cnt == 1) { print "press N to test this dispatch table\n", "press c to continue (no action taken)\n", "press q to Exit (abort completely)\n"; chomp(my $selection = <STDIN>); my $code = $dispt{$selection} || $dispt{'error'} ; $code->(); } } sub N { my $returnval = "hpdb \...@_<"....@_.">"; return $returnval; } -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/