Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: writing blank array to file?

by wog (Curate)
on Jun 18, 2001 at 20:13 UTC ( #89351=note: print w/replies, xml ) Need Help??

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.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://89351]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2022-01-29 05:04 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (74 votes). Check out past polls.