http://www.perlmonks.org?node_id=4891


in reply to How do I write to a file?

Always, ALWAYS check the return value of a command such as open: open INPUT "myfile.txt" || die "Cannot open file: $!"; This will save you hours of aggregate troubleshooting when your program fails silently. (The special variable $! contains the error message. Print it to discover why the file couldn't be opened.)

Replies are listed 'Best First'.
Re: Answer: How do I write to a file?
by I0 (Priest) on Apr 08, 2002 at 06:22 UTC
    #I think you meant either open INPUT, "myfile.txt" or die "Cannot open file: $!"; #or (open INPUT, "myfile.txt") || die "Cannot open file: $!"; #"myfile.txt" || die "Cannot open file: $!" is always true