This will be slower than necessary since it will keep testing after $entryVariable is found. A faster version could use first() from List::Util:sub addfor{ my ($mainwidget,$entryVariable) = @_; unless (grep { $_ eq $entryVariable } @history) { $widget{'forwardlistbox'}->insert(end => $entryVariable); push @history, $entryVariable; } }
Note that your code may have problems: I don't see where @history is getting initialized and you're not using $mainWidget in the subroutine. I don't know if these are real problems or not but they might be.use List::Util 'first'; sub addfor{ my ($mainwidget,$entryVariable) = @_; unless (first { $_ eq $entryVariable } @history) { $widget{'forwardlistbox'}->insert(end => $entryVariable); push @history, $entryVariable; } }
-sam
In reply to Re: match a word in an words' array
by samtregar
in thread match a word in an words' array
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |