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

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

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