Sigh. Others have answered the question and I am ( once again ) simply throwing pop bottles from the bleachers.
open(FILE, ">folder/${name}/${date}.txt");
Why are you doing this? I know, you are making sure Perl Does the Right Thing and you have been bitten by ( I am guessing here ) shell programming.

In Perl, legal variables names are must start with an alphabetic character or an underscore. After that, it can be lots of things. It cannot be, though, / or ".". Which means you can write that line as

open(FILE, ">folder/$name/$date.txt");
which is easier on my poor eyes. It flows, it makes sense.

Of course, I also fall off the end of this statement. Especially when you open it for writing. You are not checking to see if you open the file. This will annoy you later, believe me. A wise monk ( or at least a monk who is tired of being bitten by this ) would say

open(FILE, ">folder/$name/$date.txt") || die("Couldn't open file for w +riting: $!");
which will not only protect you from trying to write to an unopened file, but it will also tell you why it didn't work.

Of course, a stylish monk would take offense to all the parens in there. Actually, a stylish monk is really lazy and hates the cording necessary to make ( and ). So s/he would say instead

open FILE, ">folder/$name/$date.txt" or die "Couldn't open file for re +ading:$!";
I would take this one step further and make the error message more informative and say
my $filename = "folder/$name/$date.txt"; open FILE, ">$filename" or die "Couldn't open $filename for writing: $ +!";
This would tell me what the code was trying to open so I could figure out what I screwed up this time.

mikfire


In reply to RE: More File/Directory Trouble by mikfire
in thread More File/Directory Trouble by zdog

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.