cleen has asked for the wisdom of the Perl Monks concerning the following question:

Im having a problem which is seeminly driving me nutty..I am currently writing an application in which uses the Curses::Forms module, in order to dynamically change menu style, content, size I must make a call to a localized sub routine

my $form = Curses::Forms->new({ 'Y' => 1, 'X' => 0, 'LINES' => $LINES - 2, 'COLS' => $COLS }); $form->add( { 'type' => 'list_box', 'name' => 'Orders', 'ypos' => 0, 'xpos' => 25, 'cols' => ($COLS - 27), 'lines' => 8, 'title' => ' Orders ', 'list' => ["blah" +,"blah2"] }, { 'type' => 'txt_field', 'name' => 'Status', 'ypos' => 10, 'xpos' => 25, 'cols' => $COLS - 27, 'lines' => $LINES - 14, 'title' => ' Status ', 'content' => '(no record selected)' }, { 'type' => 'list_box', 'name' => 'Menu', 'ypos' => 0, 'xpos' => 0, 'cols' => $COLS - 57, 'lines' => $LINES - 4, 'title' => ' Menu ', 'list' => +[], }, ); $form->tab_order(qw( Orders Menu)); $form->bind( ["Orders", "[ \n]", "Mod_Oth", \&get_menu, "Me +nu"], ["Orders", "[\n]", "Nxt_Wdgt"], ["Menu", "[ \n]", "Mod_Oth", \&do_somthing, "S +tatus"], ["Menu", "[hH]", "Mod_Oth", \&get_help, "Menu" +], ["Orders", "[rR]", "Mod_Oth", \&refresh_win, " +Orders"] ); $form->set_defaults ( DEF_FUNC => \&clock); $form->activate();


This is how the form is set up. Now lets use the routine &do_somthing, which is where my problem is coming from, whenever on the "Menu" form the enter key is pressed, it calls the sub routine do_somthing. do_somthing is local and looks like this

local *do_somthing = sub { my $list_ref = shift; my $menu_ref = shift; my $status_ref = shift; my $selected; my $blah; my $selected_num = $$menu_ref{'selected'}; my ($id, $menu) = split(/ /,$$menu_ref{'title'}); $selected = $$menu_ref{'list'}{$selected_num}; print "$selected\n"; $selected =~ s/\s+$//g; if ($selected eq "VIEW CONFIGURATION") { $blah = &external_subroutine($id); $$status_ref{"content"} = $blah; } elsif { $$status_ref{"content"} = "HRMM"; } }; ..... ..... ..... outside this whole block of code sub external_subroutine { my $id = @_; # IM THINKING THIS MAY BE THE PROBLEM $id =+ 10; return $id; }


so the code takes in references from what was passed to it from the bind(), and Im trying to change the content of the "status" window to the contents of the return value of the &external_subroutine Ok no problem right? It works great the FIRST time you press the menu item "view configuration", but after that all my references seem to be overwritten or just have disappeared so If I select another menu item I dont get the elsif it just doesnt do anything. I know this HAS to do somthing with localized subroutines and calling external sub routines will overwrite the current references or somthing wierd like that...I dont know, if anyone can help it would be of great help to me. Or you can just -- me becuase I was way to confusing in explaining my problem

Replies are listed 'Best First'.
Re: Calling External Subroutines from a local sub.
by cleen (Pilgrim) on Apr 09, 2001 at 23:24 UTC
    bah, dont answer this question, once again, as per usual I have answered my own question, i was over-writing references, god I can be an idiot sometimes.
Re: Calling External Subroutines from a local sub.
by princepawn (Parson) on Apr 09, 2001 at 23:26 UTC
    Hi cleen. A few things, though I may not be able to provide you with the final answer you need:

    my $id = @_;
    sets $id to the number of elements in @_ So you should do one of these things to do what you want:
    my ($id) = @_; my $id = $_[0]; my $id = shift;

    The other thing is why did you use a typeglob to define that sub instead of simply doing

    sub do_something { ... }

    It would've done the same thing with less added syntax...

    Then you state:

    It works great the FIRST time you press the menu item "view configuration", but after that all my references seem to be overwritten or just have disappeared so If I select another menu item I dont get the elsif it just doesnt do anything.

    do this:

    $subref = \&do_something;
    And then print $subref before and after you think it has disappeared.