You are using single quotes which tell Perl to NOT interpret what is
between the single quotes.  SO '$2 $1' becomes $2 $1 in the new variable
while "$2 $1" would become the values of $2 and $1.

Wags ;)

-----Original Message-----
From: Beau E. Cox [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, August 28, 2002 11:07
To: [EMAIL PROTECTED]
Subject: Interpolation problem


Hi all -

I can't figure this one out. I have a requirement
to grab from some sort of input the elements of a regular
expression and execute it. All is fine except when I use
$1, $2, ... in the substitution, as:

#!/usr/bin/perl
use strict;
use warnings;

$_ = 'beau cox';
my $match = '(\w+)\s+(\w+)';
my $sub = '$2 $1';
s /$match/$sub/;
print "regex: s/$match/$sub/\nresult: $_\n\$1: $1\n\$2: $2\n";

gives the output:

regex: s/(\w+)\s+(\w+)/$2 $1/
result: $2 $1
$1: beau
$2: cox

I know the problem has something to do with my "$2 $1" being
inside $sub, but...?

Aloha => Beau.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to