array reference

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

  1. tamiry

    tamiry Guest

    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;

    but I wish to know if it's possible to do in a single command,
    something like
    unfortunately, it doesn't work.

    tamiry, May 24, 2005
    1. Advertisements

  2. ReadList( [ GetList() ] );

    perldoc perlref

    Note that doing this gains you nothing in legibility.

    Mark Clements, May 24, 2005
    1. Advertisements

  3. tamiry

    phaylon Guest

    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,
    phaylon, May 24, 2005
  4. tamiry

    tamiry Guest

    thanks guys
    I was trying
    too. I got close, but not close enough untill now.
    tamiry, May 24, 2005
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.