reference to anonymous scalar

Discussion in 'Perl Misc' started by Peng Yu, Jun 5, 2010.

  1. Peng Yu

    Peng Yu Guest

    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;
    Peng Yu, Jun 5, 2010
    #1
    1. Advertising

  2. Peng Yu

    C.DeRykus Guest

    On Jun 5, 7:46 am, Peng Yu <> 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
    C.DeRykus, Jun 5, 2010
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Reporter
    Replies:
    3
    Views:
    465
    Mike Schilling
    May 12, 2007
  2. Eric Mahurin
    Replies:
    4
    Views:
    238
    David A. Black
    May 6, 2005
  3. Clint Olsen
    Replies:
    6
    Views:
    342
    Jeff 'japhy' Pinyan
    Nov 13, 2003
  4. Mark

    Replace scalar in another scalar

    Mark, Jan 27, 2005, in forum: Perl Misc
    Replies:
    4
    Views:
    156
    Arndt Jonasson
    Jan 27, 2005
  5. J Krugman
    Replies:
    17
    Views:
    225
    Anno Siegel
    Mar 15, 2005
Loading...

Share This Page