I am trying to do a simple string substitution, but could not succeed.
#!/usr/bin/perl
$var = "M4S120_appscan";
$var1 = "SCANS";
$path =~ s/$var/$var1/;
print "Path is $path"
The output should be "Path is SCANS"
, but it prints nothing in 'output'.
To replace "M4S120_appscan" with "SCANS" in a string:
$str = "Path is M4S120_appscan";
$find = "M4S120_appscan";
$replace = "SCANS";
$str =~ s/$find/$replace/;
print $str;
If this is what you want.
Substitution is a regular expression search and replace. Kindly follow Thilo:
$var = "M4S120_appscan";
$var =~ s/M.+\_.+can/SCANS/g; # /g replaces all matches
print "path is $var";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With