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

Sorry venerable monks this has a lot of code and output but I have no idea why I'm getting the result I am. The sub routine sets up a group of Entry boxes and tries to add default values to the boxes which it extracts from a hash. This works unless the value I'm trying to insert is -1. In which case I get -1-1 any other value outputs fine and dandy. Does perl have a special meaning for -1 if so how can I get round the problem?
As a side note I had worked without problems with this sub for sometime, and it was only luck or bad luck that I came upon a parameter of -1 in the test data.
sub build_param_input{ my $params = @_; my $file = SBSTESTFUNCTIONS::get_XML_file_name('FILE'=>"$program_ +name.pm"); $params = SBSTESTFUNCTIONS::get_vars_hash('FILE'=>$file); print Dumper(\%$params); # testing #output #$VAR1 = { # 'STOP_AFTER' => [ # 'G2155_STOP', # '-1', # undef # ], # 'START_FROM' => [ # 'G2155_START', # '-1', # undef # ], # 'RESPONSE' => [ # 'G2155_RESPONS', # 'G2155_RESPONS', # undef # ], # 'SERVICE' => [ # 'G2155_SERVICE', # 'ENQSYSSV', # undef # ], # 'SHARED' => [ # 'G2155_SHARED', # 'Y', # undef # ] # }; my $count; foreach my $key (keys(%$params)){ $count++; my $name = $lf1->Entry(-textvariable=>$key); $name->insert('e',$key); my $pinput= $lf1->Entry(-textvariable=>$$params{$key}[1]); $pinput->insert('e',$$params{$key}[1]);#Inserts the -1-1 but o +ther values OK. print "$$params{$key}[1]\n"; #to test #Output to stdout #-1 #-1 #G2155_RESPONS #ENQSYSSV #Y $name->grid(-row=>$count, -column=>1); $pinput->grid(-row=>$count, -column=>2); } $count = undef; }

Replies are listed 'Best First'.
Re: Printing -1 in a Tk Entry.
by gri6507 (Deacon) on Jun 02, 2004 at 13:17 UTC
    It looks like you are creating an Entry per each hash entry. Each Entry has a textvariable associated with it, which puts the value from the hash into the Entry. You then insert the same value yet again into the Entry. I think you just need to get rid of the insert statement. I tried it on this code

    use Tk; use strict; my %params = ( a => [ "blah1", "hello" ], b => [ "blah2", "-1" ] ); my $mw = MainWindow->new(-title => 'Play w/form'); foreach my $key (keys(%params)){ my $entry = $mw->Entry(-textvariable=>\$params{$key}[1])->pack(); #$entry->insert('e',$params{$key}[1]); #unnecessary insert } MainLoop;
      I've tried this and nothing appears in the Entry box. As I understand it the -textvariable=>$var asscociates the value typed in, to the variable $var but does not display it.
        Your understanding is incorrect. Take a look here.
Re: Printing -1 in a Tk Entry.
by zentara (Cardinal) on Jun 02, 2004 at 13:16 UTC
    It would be helpful if you could post a small working program that demonstrates your problem.

    I'm not really a human, but I play one on earth. flash japh
      Thanks to both replies I have found the answer but there was still something weird going on. The fault lay in the fact that the textvariable should be a reference to variable not $$params{$key}1 as i had used however why this only doubled up the -1 I still have no idea. I tried to replicate the behavior in a small prog but found I could not get the same result. Thanks for your considerations