Although, unfortunately, I don't quite understand what the problem at hand is or what exactly it is that you are asking, try this code:
sub addfor{
my ($mainwidget,$entryVariable) = @_;
my $ex = 0;
if (grep(/^$entryVariable$/,@history)) {
$mainwidget->messageBox('-icon' => 'error', -type => 'OK', -t
+itle => 'Error for input',-message=>"duplicate input");
$ex= 1;
}
unless ($ex){
$widget{'forwardlistbox'}->insert('end', $entryVariable);
push (@history, $entryVariable);
}
}
Here, I got rid of the foreach() loop and replaced it (and consequent
if statement) with a single grep. Also, your original loop would make a message box (annoying pop up i'd guess) appear every time the entry variable is found in the history array. This is no good since also the error message is staying the same all the time.
Also, you didn't have to use strings for defining true/false state. Just use a simple 1 or 0.
UPDATE: changed the grep line. Was passing scalar instead of an EXPR. However, this was done long before you've made your reply,
samtregar. In fact as soon as I hit the 'Submit' button the first time and spotted the same slip. And excuse me, but that's a pretty rough language you chose to use there buddy!
UPDATE: Thanks
samtregar, it really wasn't my intent to make an 'ass' out of you nor anyone else on PM. I have too much respect for fellow monks to do anything harmful.
|
"There is no system but GNU, and Linux is one of its kernels." -- Confession of Faith
|