Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: shrinking the path

by prad_intel (Monk)
on Feb 01, 2005 at 11:18 UTC ( [id://426862]=note: print w/replies, xml ) Need Help??


in reply to Re: shrinking the path
in thread shrinking the path

Thanks bart !

it worked , even before posting i tried what boris had suggested but that lead to a failure why ?

prad

Replies are listed 'Best First'.
Re^3: shrinking the path
by bart (Canon) on Feb 01, 2005 at 13:03 UTC
    The difference is in my use of quotemeta, \Q inside the regex. His version uses your string as a regex, mine turns it into a literal search.

    Here is a simple demo for what's going on:

    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
    Result:
    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 ":".

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://426862]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-26 00:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found