Constructing a scalar reference

Discussion in 'Perl Misc' started by Chet Butcher, Jun 7, 2009.

  1. Chet Butcher

    Chet Butcher Guest

    Hi

    In the following sequence

    $r = {}; # a hashref
    $r = []; # an arrayref
    $r = ?; # a scalar ref

    What is ? ? I want to pass a ref to a scalar (pass by reference)
    without resorting to

    my $r;
    mySub( \$r );

    I just want to use

    my $r = (something);
    mySub( $r );

    to be consistent with

    my $r = {}; # or my $r = [];
    mySub( $r );

    I know it's not a big drama on the surface, but I'm trying to overload
    the method to return various results depending on the reference type,
    and I dont want the \ in some calls and not others.

    Thanks
     
    Chet Butcher, Jun 7, 2009
    #1
    1. Advertising

  2. Chet Butcher <> wrote:

    > In the following sequence
    >
    > $r = {}; # a hashref
    > $r = []; # an arrayref
    > $r = ?; # a scalar ref
    >
    > What is ? ?



    Troll alert!

    This was posted here in August 2006 and again last January...


    --
    Tad McClellan
    email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
     
    Tad J McClellan, Jun 7, 2009
    #2
    1. Advertising

  3. Chet Butcher <> writes:
    > In the following sequence
    >
    > $r = {}; # a hashref
    > $r = []; # an arrayref
    > $r = ?; # a scalar ref
    >
    > What is ? ? I want to pass a ref to a scalar (pass by reference)
    > without resorting to
    >
    > my $r;
    > mySub( \$r );
    >
    > I just want to use
    >
    > my $r = (something);
    > mySub( $r );
    >
    > to be consistent with
    >
    > my $r = {}; # or my $r = [];
    > mySub( $r );
    >
    > I know it's not a big drama on the surface, but I'm trying to overload
    > the method to return various results depending on the reference type,
    > and I dont want the \ in some calls and not others.


    Why did you redirect followups to comp.lang.c?

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Jun 7, 2009
    #3
  4. Chet Butcher

    Phil Carmody Guest

    Chet Butcher <> writes:
    [SNIP - nothing of interest to the newsgroup where you directed follow-ups]

    Hello "tea pot". You're still an idiot, even after you've morphed.
    What a sad and sorry life you must lead.

    Phil
    --
    Marijuana is indeed a dangerous drug.
    It causes governments to wage war against their own people.
    -- Dave Seaman (sci.math, 19 Mar 2009)
     
    Phil Carmody, Jun 9, 2009
    #4
    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. Eric Mahurin
    Replies:
    4
    Views:
    256
    David A. Black
    May 6, 2005
  2. Clint Olsen
    Replies:
    6
    Views:
    388
    Jeff 'japhy' Pinyan
    Nov 13, 2003
  3. Mark

    Replace scalar in another scalar

    Mark, Jan 27, 2005, in forum: Perl Misc
    Replies:
    4
    Views:
    179
    Arndt Jonasson
    Jan 27, 2005
  4. Dibosia

    constructing a scalar reference

    Dibosia, Aug 21, 2006, in forum: Perl Misc
    Replies:
    11
    Views:
    189
    Paul Lalli
    Aug 22, 2006
  5. Chet Butcher

    Constructing a scalar reference

    Chet Butcher, Jan 30, 2009, in forum: Perl Misc
    Replies:
    4
    Views:
    122
Loading...

Share This Page