Dear Monks (apologies for the long title),

My quest for perl enlightenment has once again brought me to the Monastery seeking wisdom.
I'm searching for a way to prevent pushing duplicate information into an array... here's an example:

I'm reading a book looking for three words on the same line... say "perl", "monks", and "rule".
I come across the line "I think Perl Monks Rule". So I use the regular expression below to push that entire line into an array for later use:

my @Book = (); my @MatchFound = (); foreach (@Book) if ( $_ =~ /\bPerl\b/i && /\bMonks\b/i && /\bRule\b/i ) { push @MatchFound, $_; }
On the next page of the book, I run across the same line "I think Perl Monks rule",
but I don't want to push it into the array @MatchFound because it's already there.

How do I scan the array @MatchFound prior to pushing information to it, to determine if that information is already there?

Or, would it be better to wait until I finish the book, then delete all duplicate lines from @MatchFound (which I have no idea how to do either)?

I know there has to be a term for this type of search... something really abstract like unique array identifier or something. Any ideas?


In reply to Preventing duplicate info from being pushed into an array by neo1491

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.