There is probably a better way, but this is tested and does work.
I could get it to eval the value of $1 into $str either.
Using qr// to put your regex into a string save much bother of escaping thing and saves you from needing to eval the regex.
#! perl -sw use strict; my $exp= qr/^DMSC0022\s+\S+\s+(\w+)$/; my $str='Logfile_Connection_Lost Hostname: ?'; $_="DMSC0022 X10 oswald"; if ( m/$exp/) { my $bit = $1; $str =~ s/\?/$bit/; print $str; }
In reply to Re: Regex frustration
by BrowserUk
in thread Regex frustration
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |