http://qs321.pair.com?node_id=89351


in reply to writing blank array to file?

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.