M
mike
hi
how can i use pattern matching with PERL to validate a user keying in
a unix pathname
I wish to make sure that
1) pathname must be in the form /dir1/dir2/filname ( any amount of
directory levels)
2) user cannot use other characters for the path separator, only can
use "/"
here is my piece of code
printf "Enter pathname of the file(eg. \/path\/path2 ): ";
my $path = <STDIN>; chomp($path);
@pathname = split("/", $path);
foreach $split_path ( @pathname )
{
chomp($split_path);
last if $split_path !~ /[a-zA-Z0-9]+/ or $split_path !~ /\//;
}
Am i doing it correctly or is the check sufficient??
thanks..
how can i use pattern matching with PERL to validate a user keying in
a unix pathname
I wish to make sure that
1) pathname must be in the form /dir1/dir2/filname ( any amount of
directory levels)
2) user cannot use other characters for the path separator, only can
use "/"
here is my piece of code
printf "Enter pathname of the file(eg. \/path\/path2 ): ";
my $path = <STDIN>; chomp($path);
@pathname = split("/", $path);
foreach $split_path ( @pathname )
{
chomp($split_path);
last if $split_path !~ /[a-zA-Z0-9]+/ or $split_path !~ /\//;
}
Am i doing it correctly or is the check sufficient??
thanks..