• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

variable in string surrounded by underscore

L

Larry__Weiss

#2
Contrast to

$s = 1
"_$($s)_"

or

$s_ = 1
"_$($s_)_"

Underscore is a character allowed in a variable name.

- Larry


On 4/5/2010 1:08 PM, Dan Holmes wrote:

> Why does this produce "_" instead of "_1_"
>
> PS D:\ts\ts5_2_2> $s = 1
> PS D:\ts\ts5_2_2> "_$s_"
> _
 

My Computer

J

Joachim Pense

#3
Am 05.04.2010 20:08, schrieb Dan Holmes:

> Why does this produce "_" instead of "_1_"
>
> PS D:\ts\ts5_2_2> $s = 1
> PS D:\ts\ts5_2_2> "_$s_"
> _
Because _ is scanned as a letter, so it is looking for a variable $s_,
which doesn't exist und results in an empty string. Works exactly like
that in Perl, or the Unix shells.

To get it right, write "_{$s}_".

Joachim
 

My Computer