Others have pointed out some of your other problems.

That's not what's happening. First of all you're better of using splice then delete for this, or using some sort of foreach loop to not write undef items of the array to the file.

What you are doing is opening the file $ARGV[0] for writing, clobbering the previous file, forgetting to check the return value (open can and will fail, be sure not to ignore it!), and then you are trying to read from this write only filehandle, and somehow not noticing that this is happening, probably because you don't have warnings on to get a message like: Filehandle  TO_WRITE opened only for output.... Nevertheless, the read attempt returns undef and you never do anything in the while loop.

You should, among other things, get rid of the while loop and probably use splice, and use -w and strict.

update (in response to malloc's node): Yes, you do want to clobber the file in this case. The reason I mention that its happening is that it (combined with how the print is never ran) explains why the file is blank.


In reply to Re: writing blank array to file? by wog
in thread writing blank array to file? by dusk

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.