On Jun 5, 7:46*am, Peng Yu <pengyu...@gmail.com> wrote:
> 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;
--
Charles DeRykus
|