Have a requirement to open every file found in a specific directory, perform a simple substitution, and write it back out. Will do the output writing routine later but right now the routine below keeps dying when trying to open the first file in the array. I've checked and the files - there are 6 of them - contain data and are chmod-ed to 644. User who created the files is the same as the owner of this Perl script.
Here's the script:
Would appreciate assistance in figuring this one out - it doesn't make sense to me.
Tnx.
Tom
"My mind is like a steel whatchamacallit ...
Here's the script:
Code:
#!/bin/perl
$source_dir = "/interface/ftp/files_in";
$target_dir = "/interface/ftp/files_out";
### get list of files to be processed into filenames array
opendir( DIR, $source_dir ) || die "Can't open source directory!\n";
local( @filenames ) = readdir( DIR );
closedir( DIR ) || die "Can't close source directory!\n";
### process each file, one at a time, except '.' and '..' files
foreach $myfile ( @filenames )
{
print "File being processed is $myfile\n";
if ( $myfile eq "." || $myfile eq "..") { print "IGNORED\n"; next };
unless (open(INFILE, $source_dir/$myfile))
{
die ("Input file $source_dir/$myfile cannot be opened\n");
}
$line = <INFILE>; [COLOR=red]###NEVER GETS HERE!!!!![/color]
while ($line ne "")
{
if (substr($line,1,3) eq "fac") ### should be on line 3 of the file
{
$facility = substr($line,5,1);
print "Facility code : $facility\n";
}
if (substr($line,1,15) eq "report_subtitle") ### should be on line 8 of the file
{
print "Original report subtitle line: $line\n";
$rs = substr($line,17);
$line = "%report_subtitle%" . $facility . $rs;
print "Changed report subtitle line : $line\n";
}
}
$line = <INFILE>;
}
close INFILE;
}
Would appreciate assistance in figuring this one out - it doesn't make sense to me.
Tnx.
Tom
"My mind is like a steel whatchamacallit ...