So let me get this straight:
- You got an error message while attempting to open your file (via die)
- If you print to the console instead of to your file, everything succeeds
- If you try to print to your file (which failed to open per #1), it fails
Hmm...
Did you try looking at the error message? What did the error message say? If you got an error message while attempting to open your file, I would probably have to say that the file was not opened, which explains why your print statement to the file failed to work.
Note that "die" isn't giving you an error message. It simply relays the error message to you and stops execution of your script. If the open call failed, you would not know about it unless you checked the return value of open, and did something with it (in this case, we use 'or die ...' to print out an error message if something went wrong and exit the script).
Clearly, your open is failing, for the reasons explained by the error message you received.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.