use warnings;
use strict;
my $count = 1;
my @test_characters = qw( * . " / \ [ ] : ; | );
push @test_characters, ' ';
push @test_characters, ',';
foreach my $char (@test_characters){
print "char = \'$char\'\n";
my $logfile = $0;
$logfile =~ s/\.pl$/_$count-$char---\.log/;
$count++;
print "logfile = >$logfile<\n";
if(not open my $fh_log, ">", $logfile) {
print "Error *** Couldn't open logfile for output: $logfile - $! : $^E ---\n",'-'x79,"\n";
next;
}
else {
print "-- Opened logfile for output: $logfile ---\n";
if( not print $fh_log "-- Opened logfile for output: $logfile ---\n",'-'x79,"\n" ){
print "Couldn't print to file handle.$!--\n";
}
print '-'x79,"\n";
}
}
####
char = '*'
logfile = >testlog_1-*---.log<
Error *** Couldn't open logfile for output: testlog_1-*---.log
- Invalid argument :
The filename, directory name, or volume label syntax is incorrect ---
-------------------------------------------------------------------------------
char = '.'
logfile = >testlog_2-.---.log<
-- Opened logfile for output: testlog_2-.---.log ---
-------------------------------------------------------------------------------
char = '"'
logfile = >testlog_3-"---.log<
Error *** Couldn't open logfile for output: testlog_3-"---.log
- Invalid argument :
The filename, directory name, or volume label syntax is incorrect ---
-------------------------------------------------------------------------------
char = '/'
logfile = >testlog_4-/---.log<
Error *** Couldn't open logfile for output: testlog_4-/---.log
- No such file or directory :
The system cannot find the path specified ---
-------------------------------------------------------------------------------
char = '\'
logfile = >testlog_5-\---.log<
Error *** Couldn't open logfile for output: testlog_5-\---.log
- No such file or directory :
The system cannot find the path specified ---
-------------------------------------------------------------------------------
char = '['
logfile = >testlog_6-[---.log<
-- Opened logfile for output: testlog_6-[---.log ---
-------------------------------------------------------------------------------
char = ']'
logfile = >testlog_7-]---.log<
-- Opened logfile for output: testlog_7-]---.log ---
-------------------------------------------------------------------------------
char = ':'
logfile = >testlog_8-:---.log<
-- Opened logfile for output: testlog_8-:---.log ---
-------------------------------------------------------------------------------
char = ';'
logfile = >testlog_9-;---.log<
-- Opened logfile for output: testlog_9-;---.log ---
-------------------------------------------------------------------------------
char = '|'
logfile = >testlog_10-|---.log<
Error *** Couldn't open logfile for output: testlog_10-|---.log
- Invalid argument :
The filename, directory name, or volume label syntax is incorrect ---
-------------------------------------------------------------------------------
char = ' '
logfile = >testlog_11- ---.log<
-- Opened logfile for output: testlog_11- ---.log ---
-------------------------------------------------------------------------------
char = ','
logfile = >testlog_12-,---.log<
-- Opened logfile for output: testlog_12-,---.log ---
-------------------------------------------------------------------------------
##
##
Volume in drive D is APPS
Volume Serial Number is XXX
Directory of D:\scripts\clear_dmp_files\test
10/09/2019 03:28 PM .
10/09/2019 03:28 PM ..
10/09/2019 03:28 PM 0 testdir.txt
10/09/2019 03:01 PM 833 testlog.pl
10/09/2019 03:27 PM 136 testlog_11- ---.log
10/09/2019 03:27 PM 136 testlog_12-,---.log
10/09/2019 03:27 PM 135 testlog_2-.---.log
10/09/2019 03:27 PM 135 testlog_6-[---.log
10/09/2019 03:27 PM 135 testlog_7-]---.log
10/09/2019 03:27 PM 0 testlog_8-
10/09/2019 03:27 PM 135 testlog_9-;---.log
10/09/2019 03:27 PM 2,629 testlog_out.txt
10 File(s) 4,274 bytes
2 Dir(s) 129,251,168,256 bytes free