You never increment $i, so you never will never reach the code where you compare the number to the array

I could stop the program with ctrl-C without any problems. ctrl-Z would make the program run as a background prozess here on linux, don't know what you have running

Even if you had changed $i you would not get the right results. You use exit to presumably exit the loop, that is done with last. exit exits the program.

Also your logic is wrong. When it compares the first value in the array with the new value and it is different, it already pushes the new value into the array. But you have to wait until you compared the new value to ALL values before you can push it. Ergo you need to wait until after the loop before you can add that new value

Please indent correctly. Your program is very hard to read

Please 'use warnings;'

To find out what is happening in a program, put print statements into it and print out variable values. If you had inserted a print statement just before the loop (to find out what is going on) you would have found out that that part of the code was never executed.


In reply to Re: question on Arrays by jethro
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.