Ok. Now I understand this better.
Use the command prompting loop to reject invalid syntax of the input.
Below I reject input lines that have a double // or \\.
use strict;
use warnings;
my $dir;
while ( (print "enter directory; "), $dir=<STDIN> and $dir =~ /\\\\|\/
+\//g)
{
print "invalid directory syntax... double ", '// or \\\\', " not al
+lowed!\n";
}
$dir =~ s/^\s*|\s*$//g; #remove leading and trailing spaces
print "INPUT LOOP says $dir\n";
__END__
C:\Monks>perl CommandLoopNoDoubleSlash.pl
enter directory; C:\\x
invalid directory syntax... double // or \\ not allowed!
enter directory; D:\x\temp//
invalid directory syntax... double // or \\ not allowed!
enter directory; C://x
invalid directory syntax... double // or \\ not allowed!
enter directory; C:/X
INPUT LOOP says C:/X
Now it is also possible perhaps have a sub that prompts for a valid directory and that sub continues to loop until a valid directory is entered. I would return a file handle from that sub. In that sort of case, the sub tries to open the dir name that the user entered and it works or it doesn't. Loop until the openddir() works. Remember to allow for leading and trailing whitespace for all command line entries. |