my $VAR = 'ABC@VERSION@DEF' ;
$VAR =~ s/\@VERSION\@/1.2.3.4/g ;
print "<$VAR>\n" ;
Prints <ABC1.2.3.4DEF> as expected.
=========================
Case 2)
Lets say $input_file has a line containing ABC@VERSION@DEF
And I want to replace @VERSION@ by 1.2.3.4 So I do:
`perl -pe 's/\@VERSION\@/1.2.3.4/g' -i $input_file` ;
Which chnages the content in $input_file to
ABC1.2.3.4VERSION1.2.3.4DEF
Why the difference in the two cases ?
What do I need to do to get bahavior like Case 1 in Case 2 ?
I'd suspect some special interpretation of @ at play but it's escaped - but
not sure any ideas ?
Thanks!
> s/\@VERSION\@/1.2.3.4/g
Consider a "while ( my $p=index() ){ substr(,,,) }" approach.
--
Affijn, Ruud
"Gewoon is een tijger."
> `perl -pe 's/\@VERSION\@/1.2.3.4/g' -i $input_file` ;
>
> Which chnages the content in $input_file to
>
> ABC1.2.3.4VERSION1.2.3.4DEF
>
> Why the difference in the two cases ?
>
> What do I need to do to get bahavior like Case 1 in Case 2 ?
>
> I'd suspect some special interpretation of @ at play but it's escaped
It's not escaped to the shell nor to the second invocation of perl.
@VERSION = qw(aaa bbb);
$_ = `echo perl -pe 's/\@VERSION\@/1.2.3.4/g' -i $input_file`;
$_ = `echo perl -pe 's/\\@VERSION\\@/1.2.3.4/g' -i $input_file`;
$_ = `echo perl -pe 's/\\\@VERSION\\\@/1.2.3.4/g' -i $input_file`;
system qq{perl -pe 's/\\\@VERSION\\\@/1.2.3.4/g' -i $input_file};
Take a look at 'perldoc backticks'. In particular, the sections for
What's wrong with using backticks in a void context?
How can I call backticks without shell processing?
-Joe