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

In reply to Re: match a word in an words' array by vladb
in thread match a word in an words' array by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.