On Thu, 21 Jun 2001 09:56:03 +0200, Allan Juul wrote:
>might be silly question
>how do you actually replace numbers when immidialtely following a $1, $2 or
>so?
The same way as you would insert $foo followed by "ab". See below.
>like this will return stuff23 :
>
>$a = 23;
>$_ =~ s/some (stuff)/$1$a/g
>
>i had hoped something in the vein of this would have done it:
>
>$_ =~ s/some (stuff)/$1\23/g
Well, this does work:
s/some (stuff)/$1\E23/g;
but this is the common idiom:
s/some (stuff)/${1}23/g;
Like you can append "ab" to $foo by doing:
"${foo}ab";
Er... this is NOT a symbolic reference, ${foo} works on lexical
variables (declared with "my") too, while ${'foo'} is a symbolic
reference, and does not work with lexicals. But obviously, the syntax
was inspired by it.
It is described in perldata. I quote a part of it here (edited):
As in some shells, you can enclose the variable name in braces to
disambiguate it from following alphanumerics.
$who = "Larry";
print "We use ${who}speak when ${who}'s here.\n";
Without the braces, Perl would have looked for a $whospeak
and a `$who's' variable. The latter would be the $s variable in the
(presumably) non-existent package `who'.
--
Bart.