Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Substituting a variable in s///g 2

Status
Not open for further replies.

lgeorge26

Programmer
Jun 12, 2007
2
FR
Is it possible to substitute a variable in
s///g;
i.e for eg
$var="*";
$str="abc1230-9ASA*new";

$str=~ s/$var//g;
print $str;

output should be

abc1230-9ASAnew


 
Not sure if it's the best or brightest way but:
$var= '\*';
$str='abc1230-9ASA*new';

$str=~ s/$var//g;
print $str;
 
Code:
$var = "*";
$str = "abc1230-9ASA*new";
$str =~ s/\Q$var\E//g;
print $str;

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top