in reply to To die or not to die

open FH, ">user1.cfg" or die "Couldn't open file;"

It does not matter if the user1.cfg exists prior to running the code. If it does not exist, it will be created. If it does exist, it will be overwritten. If you are unable to open the file for writing, you should not proceed with writing to the file. You will get errors when you attempt to write to a file that hasn't been opened for writing.

Replies are listed 'Best First'.
Re: Re: To die or not to die
by Popcorn Dave (Abbot) on Oct 28, 2002 at 21:16 UTC
    You're right. After thinking about what you had said, I should have put:

    open FH, "user1.cfg" not ">user1.cfg"

    Well at least that is what I was trying for initially.

    There is no emoticon for what I'm feeling now.

      You should better have said open FH, "<user1.cfg" or, really, open FH, "<", "user1.cfg". Make it a habit of using the three-argument form of open - esp since I suspect that in this case, your filename will not be hardwired but dynamic and maybe even derived from user input. In that case, the two-argument form may leave you open to a range of problems from "simple" bugs to outright security holes.

      Makeshifts last the longest.