in reply to pattern matching and interpolation...
my $ndata = "\\\\MYSERVER\\C\$\\Temp"; # \\MYSERVER\C$\Temp my $quoted_ndata = quotemeta($ndata); # \\\\MYSERVER\\C\$\\Temp m/$quoted_ndata/
or
my $ndata = "\\\\MYSERVER\\C\$\\Temp"; # \\MYSERVER\C$\Temp m/\Q$ndata\E/
You want to locate $ndata at the begining of $line, so you need to add ^, as follows:
m/^\Q$ndata\E/
Don't use $'. It will slow down every regexp in your program that doesn't have captures. Use the following instead:
if ($line =~ m/^\Q$ndata\E(.*)/) { my $ndir = $1; print "$ndir\n"; }
Finally, searching for a constant string using a regexp is inefficient. Use the following instead:
if (index($line, $ndata) == 0) { my $ndir = substr($line, length($ndata)); print "$ndir\n"; }
Updated.
|
|---|