in reply to Search & Replace repeating characters
my $script_dir = 'C:\\temp\\\\'; print "1. $script_dir\n"; $script_dir =~ s{\\+}{/}g; print "2. $script_dir\n"; $script_dir =~ s{/$}{}g; print "2. $script_dir\n";
You can use transliteration with shrinking instead of substitution in the first step:
$script_dir =~ tr{\\}{/}s;
It's also possible to do everything in one step, but we're entering a golf course here:
Update: Talking about golf, this is shorter:$script_dir =~ s{\\+(?=(.)?)}{"/"x defined $1}ge;
$_ = s/\\+$//r =~ s{\\+}{/}gr for $script_dir;
|
---|