in reply to Re^2: shrinking the path
in thread shrinking the path
Here is a simple demo for what's going on:
Result:my $string = 'c:\\Windows'; my $search = '\\W'; my $qm = quotemeta($search); my $raw = $string; $raw=~ s/$search/#/; my $cooked = $string; $cooked =~ s/\Q$search/#/; print <<"TEST" original string: '$string' search string: '$search' search string after quotemeta: '$qm' substitution without \\Q: '$raw' substitution with \\Q: '$cooked' TEST
original string: 'c:\Windows' search string: '\W' search string after quotemeta: '\\W' substitution without \Q: 'c#\Windows' substitution with \Q: 'c:#indows'As you can see, with quotemeta, it replaced the substring backslash+"W", because that's what /\\W/ searches for. Without it, it just searched for the first non-word character and replaced it — that happens to be a ":".
|
|---|