I have used perl pretty extensively in the past for file/text manipulation. So this should be straightforward. My code reads a list of files from a directory into an array (via a glob), then iteratively goes through each one and makes a modified copy in a sub-directory. Straightforward stuff. I've simplified the code down a bit in the example below:

my $dir = '/some/directory/here'; my @files = <$dir/\d{6}*>; # All the relevant files start with 6 n +umbers, so don't glob others! foreach (@files) { $inputfile = $_; [open $inputfile for reading, this code works fine] .... $outputfile = $inputfile; open NEWFILE, '>', "$dir/subdirectory/$outputfile" | die "Can't +open $dir/subdirectory/$outputfile for writing: $!"; ..... }

Any thoughts? I get the following error: "Cannot open /some/directory/here/subdirectory/314767_TJD_Appr5000_2017-01-06_13_10_03.txt for writing: at ConvertText.pl line 48.

Yes, I know the filename is somewhat long and convoluted, but it is what it is. :-)

Thanks for your guidance!


In reply to Why can't I open a file for writing? by tdilling

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.