array reference

Discussion in 'Perl Misc' started by tamiry, May 24, 2005.

  1. tamiry

    tamiry Guest

    Hi,
    I have a function returning a list. I want to pass this list
    to another function, by reference.

    this works
    my @list = GetList();
    my $listref = \@list;
    ReadList($listref);

    but I wish to know if it's possible to do in a single command,
    something like
    ReadList(\@{GetList()});
    unfortunately, it doesn't work.

    anyone?
     
    tamiry, May 24, 2005
    #1
    1. Advertising

  2. tamiry wrote:

    > Hi,
    > I have a function returning a list. I want to pass this list
    > to another function, by reference.
    >
    > this works
    > my @list = GetList();
    > my $listref = \@list;
    > ReadList($listref);
    >
    > but I wish to know if it's possible to do in a single command,
    > something like
    > ReadList(\@{GetList()});
    > unfortunately, it doesn't work.
    >
    > anyone?


    ReadList( [ GetList() ] );

    perldoc perlref

    Note that doing this gains you nothing in legibility.

    Mark
     
    Mark Clements, May 24, 2005
    #2
    1. Advertising

  3. tamiry

    phaylon Guest

    tamiry wrote:

    > but I wish to know if it's possible to do in a single command, something
    > like
    > ReadList(\@{GetList()});
    > unfortunately, it doesn't work.


    If GetList() returns a list, you have a list you want to pack into in
    arrayref. You would normaly do this by:

    my $aryref = [ 1, 2, 3 ];

    So, just set your function on the right position:

    my $aryref = [ GetList() ];

    et Voila.


    Isn't tested, but hth,
    p

    --
    http://www.dunkelheit.at/

    The first rule of project mayhem is: you do not ask questions.
    -- Fight Club
     
    phaylon, May 24, 2005
    #3
  4. tamiry

    tamiry Guest

    thanks guys
    I was trying
    ReadList(\@[GetList])
    too. I got close, but not close enough untill now.
     
    tamiry, May 24, 2005
    #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. JKop
    Replies:
    12
    Views:
    725
    Howard
    Jul 21, 2004
  2. Mara Guida

    const and array of array (of array ...)

    Mara Guida, Sep 2, 2009, in forum: C Programming
    Replies:
    3
    Views:
    521
    David RF
    Sep 3, 2009
  3. fatted
    Replies:
    2
    Views:
    163
    James Willmore
    Oct 23, 2003
  4. Tom
    Replies:
    3
    Views:
    234
    salsablr
    Dec 20, 2004
  5. Andrew Poulos

    Using an array to reference a different array

    Andrew Poulos, Dec 22, 2008, in forum: Javascript
    Replies:
    6
    Views:
    100
    Jorge
    Dec 23, 2008
Loading...

Share This Page