perl - Variable Replacement using Regex -


i want replace variable in file(temp.txt) in perl.

temp.txt

hi  $test. how you?? 

now want replace variable $test. code tried below:

open $filename, "<", temp.txt or die $!;  while (<$filename>)  {   s/$test/'abc'/g;  print; }    

it not working. can tell me doing wrong?

you need escape $ because perl thinks variable:

use warnings; use strict;  while (<data>) {     s/\$test/'abc'/g;     print; }  __data__ hi  $test. how you?? 

Comments

Popular posts from this blog

javascript - How to name a jQuery function to make a browser's back button work? -

collision detection - C++ library for mesh to mesh intersection: what is available? -

python - Django-easy-pdf: xhtml2pdf reporting reportlab 2.2+ is required, but 3.0 installed -