Picking up with the theme you were following, I got this to work. I haven't thought alot about corner cases, performance or reusability, so Grandfather's and tachyon-II's solutions are probably better.
update: apparently I'm just confused on this matter && added comment on second s/// with no effect: I didn't like doing the substitution twice just to get the end-of-line anchor to work. Perhaps some wiser monks can explain that to me. update: That was before I added chomp, so never mind . . .
#/usr/bin/perl -W
$\="\n";
use strict;
use warnings;
while (<DATA>) {
chomp;
print $_;
s/\/(?:[^\@:,\s+]*\/)(.*?)[\@:,\s+]*/\/new\/path\/$1/g;
#s/\/(?:[^\@:,\s+]*\/)(.*?)[\@:,\s+]*$/\/new\/path\/$1/g;
print $_;
print '';
}
# produces:
# C:\chas_sandbox>
# 683879resp.pl
# file /user/name/some/path/to/filename@@ dumped: replaced /user/name/
+blah/blah/filename
# file /new/path/filename@@ dumped: replaced /new/path/filename
#
# @@@@user/some/file/filename.sdc: dumped
# @@@@user/new/path/filename.sdc: dumped
__DATA__
file /user/name/some/path/to/filename@@ dumped: replaced /user/name/bl
+ah/blah/filename
@@@@user/some/file/filename.sdc: dumped
#my sig used to say 'I humbly seek wisdom. '. Now it says:
use strict;
use warnings;
I humbly seek wisdom.
|