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

Using variables within Substitution syntax 1

Status
Not open for further replies.

audiopro

Programmer
Joined
Apr 1, 2004
Messages
3,165
Location
GB
I am reading text from an external file and need to substitute the text 'XAXUSER' with contents of a scalar.
This replaces 'XAXUSER' with 'USERNAME'.
Code:
my $USER='MYUSERNAME';
my $LINK='myscript.cgi?tag=1&mak=34&user=XAXUSER';
$LINK=~ s/XAXUSER/USERNAME/g;
print "$LINK<BR>";
How do I replace 'XAXUSER' with the value of $USER?

Keith
 
The right-hand-side of a substitution regexp is equivalent to a double-quoted string, so it will interpolate the variable if you just put it in there:
Code:
$LINK =~ s/XAXUSER/$USER/g;
 
Thanks ishnid
I thought I had tried but when I look back at my notes, I had used.
Code:
$LINK=~ s/[red]$[/red]XAXUSER/$USER/g;


Keith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top