M
msciwoj
Is it possible to use substitution with parameters as arguments -
especially the replacement part?
Works for me to some extent but not with backreferences...
Let's say I'm interested in prompting user for arguments: pattern and
replacement and he would like to use equivalent of:
s/(.)\n(.)/\2\n\1/mg
Continuing, I could have two vars defined, accordingly:
$pattern='(.)\n(.)'; #$ARGV[1];
$replacement='\2\n\1'; #$ARGV[2]
and my idea is to use here:
$_ =~ s/$pattern/$replacement/mg
but it doesn't work - (instead using backreferendes, gives '\1' and
'\2' in the output, what makes sens after all). The question is how
(if only possible) to use s/// with a replacement part defined in a
variable (ie. run-time user defined string)?
Any ideas?
Thanks!
m.
especially the replacement part?
Works for me to some extent but not with backreferences...
Let's say I'm interested in prompting user for arguments: pattern and
replacement and he would like to use equivalent of:
s/(.)\n(.)/\2\n\1/mg
Continuing, I could have two vars defined, accordingly:
$pattern='(.)\n(.)'; #$ARGV[1];
$replacement='\2\n\1'; #$ARGV[2]
and my idea is to use here:
$_ =~ s/$pattern/$replacement/mg
but it doesn't work - (instead using backreferendes, gives '\1' and
'\2' in the output, what makes sens after all). The question is how
(if only possible) to use s/// with a replacement part defined in a
variable (ie. run-time user defined string)?
Any ideas?
Thanks!
m.