Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Use a hash

by kwilliams (Sexton)
on May 03, 2002 at 07:15 UTC ( #163723=note: print w/replies, xml ) Need Help??


in reply to match a word in an words' array

You should probably be using a hash in the first place. Try something like this:
sub addfor{ my ($mainwidget,$entryVariable) = @_; my %history; if (exists $history{$entryVariable}) { $mainwidget->messageBox (-icon => 'error', -type => 'OK', -title => 'Error for input', -message => "duplicate input"); } else { $widget{'forwardlistbox'}->insert ('end', $entryVariable); $history{$entryVariable} = 1; } }
Hashes are almost always the proper way to implement a set.

(Also, 'use strict;'! You've got some phantom variables floating around. I'm not sure whether $widget is the same as $mainwidget or not, and @history was unscoped.)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://163723]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2021-06-14 15:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (62 votes). Check out past polls.

    Notices?