in reply to Re^2: Replacing substrings with links
in thread Replacing substrings with links
for (values %copy) { 1 while # repeat till no replacement +left s/^($pattern)/$h_orig->{$1}/g; }
But I have trouble to come up with a test case covering the complicated implications. ( Update Anyone? )
use strict; use warnings; use Data::Dump qw/pp dd/; my $h_orig = { '/a/b/c/dt/data/SUSE/tool/0.9.0' => '/a/b/c/dt/tools/SUSE/tool/0.9.0 +', '/nfs/us' => '/usr/bin', '/a/b/c' => '/nfs/us' }; my $pattern = join "|", map quotemeta, keys %$h_orig; my %copy = %$h_orig; for (values %copy) { 1 while s/^($pattern)/$h_orig->{$1}/g; } pp $h_orig, \%copy;
-*- mode: compilation; default-directory: "d:/tmp/pm/" -*- Compilation started at Sun Feb 6 15:59:06 C:/Strawberry/perl/bin\perl.exe -w d:/tmp/pm/replace_pat2.pl ( { "/a/b/c" => "/nfs/us", "/a/b/c/dt/data/SUSE/tool/0.9.0" => "/a/b/c/dt/tools/SUSE/tool/0.9 +.0", "/nfs/us" => "/usr/bin", }, { "/a/b/c" => "/usr/bin", "/a/b/c/dt/data/SUSE/tool/0.9.0" => "/usr/bin/dt/tools/SUSE/tool/0 +.9.0", "/nfs/us" => "/usr/bin", }, ) Compilation finished at Sun Feb 6 15:59:06
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Replacing substrings with links
by choroba (Cardinal) on Feb 06, 2022 at 17:20 UTC | |
by LanX (Saint) on Feb 06, 2022 at 17:23 UTC |