in reply to Selectively replacing characters inside a string

Similar to AnomalousMonk's solution but using look-behind and -ahead assertions and tr with the "complement" flag.

use strict; use warnings; open my $logFH, q{<}, \ <<EOD or die qq{open: << HEREDOC: $!\n}; 2009/06/09 10:11:12 read error: file="/path/to/file" reason: gone 2009/06/09 12:43:27 created: file="/path/to/file" EOD while( <$logFH> ) { s{(?<= file=" ) ( [^"]+ ) (?= " )} {do { my $cap = $1; $cap =~ tr{/}{x}c; $cap }}xeg; print; }

The output.

2009/06/09 10:11:12 read error: file="/xxxx/xx/xxxx" reason: gone 2009/06/09 12:43:27 created: file="/xxxx/xx/xxxx"

I hope this is of interest.

Cheers,

JohnGG

Replies are listed 'Best First'.
Re^2: Selectively replacing characters inside a string
by markkawika (Monk) on Jun 11, 2009 at 16:54 UTC
    Thank you, JohnGG, that was exactly what I was trying to accomplish yesterday on my own, but you've done it much more succinctly than I did.