As you can no doubt deduce from the replies that you have received so far, your requirements remain vague. The question implied by your title, "check if an element exists in array", has been more than adequately dealt with. But from your later comments, this is not what you really want.

Please correct me if I'm wrong, but it seems to me that your real requirements are as follows:

What is not clear, however, is what output you want if the name occurs more than once in the file, ie for input of 'Jim' in your example, I see several possibilities:

Jim 12 # Use first occurrence Jim 57 # Use last occurrence Jim 12, 57 # List of all numbers associated with Jim Jim 69 # Jim's total 'score' Sorry, name 'Jim' occurs more than once # Or some similar warning

Based on the answers provided above, you should be able to code for any of these. What I suggest is that you now write some code, and come back to us if you still can't get it to do what you want. But please, in that case, tell us what it is that you want!


In reply to Re: check if an element exists in array by Not_a_Number
in thread check if an element exists in 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.