Maybe better to use a hash if you are going to check existence?

use strict; use warnings; ## buffering off ++$|; ## for storing numbers entered so far my %hsh; while (1){ print "Enter something (or nothing if you are bored):\n"; ## get input my $num = <>; chomp $num; ## exit infinite loop if the user hits enter twice last if (!defined$num || $num eq ''); ## check against previous input if (exists $hsh{$num}){ print "Seen >$num< before, try again.\n"; next; } else { print "Oooh >$num< is new, thanks!\n"; ++$hsh{$num}; } } print +(join "\n\t", "Finished! You entered :", sort keys %hsh);

Sample terminal:

Enter something (or nothing if you are bored): 4 Oooh >4< is new, thanks! Enter something (or nothing if you are bored): foo Oooh >foo< is new, thanks! Enter something (or nothing if you are bored): bar Oooh >bar< is new, thanks! Enter something (or nothing if you are bored): 4 Seen >4< before, try again. Enter something (or nothing if you are bored): Finished! You entered : 4 bar foo
Just a something something...

In reply to Re: question on Arrays by BioLion
in thread question on Arrays by hari9

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.