Wiggins has asked for the wisdom of the Perl Monks concerning the following question:
$a="test string x x\nFeb 1 09:12:33 ("; if ($a =~ /^\w{3}\s\s\d/m) { # /^Feb 1/ $a =~ s/^\w{3}(\s\s)\d/ /; print "<$a>\n"; }else{ print "no match\n"; } #<x x Feb 1 09:12:33 (>
It seem intuitive that a grouped substring would be the target of a substitution, if it exists for no other purpose. Or how about:my $var = 'testing'; $_ = 'In this string we are $var the "e" modifier.'; s/(\$\w+)/$1/ee; print; >In this string we are testing the "e" modifier.
So, is there a simple way to do substitution within a context?$a=~ s/$a =~ s/^\w{3}(\s\s)\d/$1/ /; #3 partr substitute like sed, $ +1 with a space?
It is always better to have seen your target for yourself, rather than depend upon someone else's description.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: contextual substitution with s///?
by BrowserUk (Patriarch) on Feb 01, 2013 at 16:27 UTC | |
|
Re: contextual substitution with s///?
by choroba (Cardinal) on Feb 01, 2013 at 16:13 UTC | |
|
Re: contextual substitution with s///?
by toolic (Bishop) on Feb 01, 2013 at 16:18 UTC | |
|
Re: contextual substitution with s///?
by mbethke (Hermit) on Feb 01, 2013 at 16:33 UTC |