Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > reference to anonymous scalar

Reply
Thread Tools

reference to anonymous scalar

 
 
Peng Yu
Guest
Posts: n/a
 
      06-05-2010
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;
 
Reply With Quote
 
 
 
 
C.DeRykus
Guest
Posts: n/a
 
      06-05-2010
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is this a local anonymous class or a member anonymous class Reporter Java 3 05-12-2007 05:23 AM
object reference handle (like perl's reference to scalar) Eric Mahurin Ruby 4 05-06-2005 05:30 PM
How to make a blessable anonymous scalar ref? J Krugman Perl Misc 17 03-15-2005 10:15 PM
Replace scalar in another scalar Mark Perl Misc 4 01-27-2005 02:48 PM
Shorthand for($scalar) loops and resetting pos($scalar) Clint Olsen Perl Misc 6 11-13-2003 12:50 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57