murrayn has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to develop a config file manager. I need, initially, to be able to read and display the current keyword=value records, edit the values, add new records and delete old records. All works fine except the delete because I don't know, at the time the delete button is pressed, the name of the particular widget to remove or the keyword to delete from my hash. My code looks like this but clearly won't work because "$_" is not static and has changed (become undefined) by the time I try to use the button.
sub cfgRuntime { if (!%runtime) { loadConfig(); } $workframe -> Label(-text=>"Folder Separator") -> grid(-row=>1, -c +olumn=>1, -rowspan=>2); $workframe -> Radiobutton(-text=>"Windows", -value=>"\\", -variabl +e=>\$runtime{'fsep'}) -> grid(-row=>1, -column=>2, -sticky=>"w"); $workframe -> Radiobutton(-text=>"Unix", -value=>"/", -variable=>\ +$runtime{'fsep'}) -> grid(-row=>2, -column=>2, -sticky=>"w"); $workframe -> Button(-text => "Save these values", -command=>[\&up +dGUIInput, "runtime", "save"]) -> grid(-row=>1, -column=>3, -sticky=>"e"); $workframe -> Button(-text => "Discard these values", -command=>[\ +&updGUIInput, "runtime", "discard"]) -> grid(-row=>2, -column=>3, -sticky=>"e"); $row = 3; for (keys %runtime) { if ($_ eq "fsep") {next} $workframe -> Label(-text=>$_) -> grid(-row=>$row, -column=>1) +; $workframe -> Entry(-width=>100, -textvariable=>\$runtime{$_}) + -> grid(-row=>$row, -column=>2); $workframe -> Button(-text=>"Delete entry", -command=> sub { delete $runtime{$_}; } ) -> grid(-row=>$row, -column=>3); $rowsin = $row; $row++; } $btnNew = $workframe -> Button(-text=>"New variable", -command=>\&newVar ) -> grid(-row=>$row, -column=>1, -sticky=>"w"); }
|
---|
Back to
Seekers of Perl Wisdom