reference to anonymous scalar

P

Peng Yu

I could use [] to define a reference to an anonymous.

$aref=[1, 2, 3];

Is there a way to define a reference to anonymous scalar instead of
having to give the scalar a name first ('x' in the following example)?

$x=10;
$y=\$x;
 
C

C.DeRykus

I could use [] to define a reference to an anonymous.

$aref=[1, 2, 3];

Is there a way to define a reference to anonymous scalar instead of
having to give the scalar a name first ('x' in the following example)?

$x=10;
$y=\$x;

As shown earlier: my $y = \10 will create a
"reference to a constant". But that differs
from a "reference to an anonymous scalar":

my $y = \10;
$$y = 15; # error: mod. of read-only...

A "reference to an anonymous scalar" though
won't produce an error:

my $y = \ do { my $tmp };
$$y = 10;
$$y = 15;
 

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

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,526
Members
44,997
Latest member
mileyka

Latest Threads

Top