Hi all,
My short program below is to read directories names form command line. It should only start with alphanumeric characters and contain no other characters except spaces, underscores and dashes.
So far what i have done below is only accepting alphanumeric characters and underscores. My question is, how do i add another character exception instead of using "\W" that reads only alphanumerics and underscores?
Thanks of any kind help.
[CODE=perl]
#!/usr/bin/perl -w
use strict;
my $path1=$ARGV[0];
my $path2=$ARGV[1];
my @dir1;
my @dir2;
#Read The First Directory
if($path1 =~ /\W/) {
print "Invalid directory!\n";
exit;
}
else {
opendir DIR1, $path1 or die exit;
@dir1 = sort readdir DIR1;
closedir DIR1;
}
#Read The Second Directory
if($path2 =~ /\W/) {
print "Invalid directory!\n";
exit;
}
else {
opendir DIR2, $path2 or die exit;
@dir2 = sort readdir DIR2;
closedir DIR2;
}
[/CODE]
My short program below is to read directories names form command line. It should only start with alphanumeric characters and contain no other characters except spaces, underscores and dashes.
So far what i have done below is only accepting alphanumeric characters and underscores. My question is, how do i add another character exception instead of using "\W" that reads only alphanumerics and underscores?
Thanks of any kind help.
[CODE=perl]
#!/usr/bin/perl -w
use strict;
my $path1=$ARGV[0];
my $path2=$ARGV[1];
my @dir1;
my @dir2;
#Read The First Directory
if($path1 =~ /\W/) {
print "Invalid directory!\n";
exit;
}
else {
opendir DIR1, $path1 or die exit;
@dir1 = sort readdir DIR1;
closedir DIR1;
}
#Read The Second Directory
if($path2 =~ /\W/) {
print "Invalid directory!\n";
exit;
}
else {
opendir DIR2, $path2 or die exit;
@dir2 = sort readdir DIR2;
closedir DIR2;
}
[/CODE]
Comment