tdilling has asked for the wisdom of the Perl Monks concerning the following question:
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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Why can't I open a file for writing?
by Perlbotics (Archbishop) on Jan 12, 2018 at 21:42 UTC | |
by tdilling (Initiate) on Jan 12, 2018 at 21:46 UTC | |
by jwkrahn (Abbot) on Jan 13, 2018 at 02:36 UTC | |
|
Re: Why can't I open a file for writing?
by haukex (Archbishop) on Jan 13, 2018 at 09:09 UTC | |
by Lotus1 (Vicar) on Jan 13, 2018 at 16:49 UTC | |
|
Re: Why can't I open a file for writing?
by Laurent_R (Canon) on Jan 13, 2018 at 15:48 UTC | |
by karlgoethebier (Abbot) on Jan 14, 2018 at 10:32 UTC |