$test <> ${test}

C

Curtis M. West

hello NG

can anyone tell me, what the difference between $test and ${test} is?

my $test = "abc";
print $test;

my $test = "abc";
print ${test};

both of the above examples do exactly the same?!

tnx & greet, curtis
 
A

anno4000

Curtis M. West said:
hello NG

can anyone tell me, what the difference between $test and ${test} is?

my $test = "abc";
print $test;

my $test = "abc";
print ${test};

both of the above examples do exactly the same?!

That's because the meaning of $test and ${test} is exactly the same.

The difference is only relevant when a variable is interpolated in a
string, as in "this is the value: $test". If what follows the
variable name could also be part of the variable name, the {}
can be used to separate the name from surrounding text:
"here$testthere" would try to interpolate the variable $testthere.
"here${test}there" interpolates $test.

Anno
 
T

Tad McClellan

Curtis M. West said:
Subject: $test <> ${test}


[
I doubt you want the diamond operator there.

I expect you meant either
$test ne ${test}
or
$test != ${test}

:)
]

can anyone tell me, what the difference between $test and ${test} is?


There are no semantic differences.

I think the syntactic difference is rather obvious. :)

my $test = "abc";
print $test;

my $test = "abc";
print ${test};

both of the above examples do exactly the same?!


Yes.
 
A

anno4000

Ferry Bolhar said:
Curtis M. West:


The braces are required in 2 cases:

1) If you use a variable name in an otherwise ambiguous context:

$name = 'Config';
print "$name_Startup"; # prints nothing, looks for a variable
$name_Startup
print "${name}_Startup"; # prints "Config"

because '_' is a valid character in variable names, the braces tell
the parse that the name of the scalar is delimited by them and the
rest is part of the string literal.

2) When you build variable names at run-time (symbolic references):

Ah, but that is a different case.
$foobar = 'FooBar';
$x = 'foo';
$y = 'bar';
print ${$x . $y}; # prints "FooBar"

This is general de-reference syntax with a symbolic reference. Here
the braces form a block whose return value (the last statement) is
taken as a reference.

That is not the case in the first example. If it were, "${name}" would
be a symref through a bareword. It wouldn't be applicable to lexical
variables.

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top