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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with substitution

Status
Not open for further replies.

denis60

Technical User
Apr 19, 2001
89
0
0
CA
Hi!

Is it possible to substitute a variable containing special characters like $ and use it as a character and not like a variable ex:
$rwrd=substr("cic $ nil",1,6);
$data =~ s/$rwrd/+\n/;

Each time a $ appear the substitution fail.
 
Sorry my exemple was too simple.

$rwrd=substr($var,1,6);
$data =~ s/$rwrd/+\n/;

$var is variable and may have a $ or not. It get $var from each line of a file.
 
Ah!

Code:
#!/usr/bin/perl

$var = '$123';

$_ = 'string of $123 text';

s/[b][red]\Q[/red][/b]$var//;

print;


Kind Regards
Duncan
 
Yes it work with single quote, but the $rwrd variable come from a substr and i think the data in it is like
$rwrd = "$123" and it fail...Sorry.
 
Duncan it's work well with a \E at the end of the variable
like \Q$var\E

Thanks a lot

Your the best
 
nice!

the site wasn't working so i couldn't reply!?


Kind Regards
Duncan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top