array reference

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

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.


Re: array reference

tamiry wrote:

Quoted text here. Click to load it

ReadList( [ GetList() ] );

perldoc perlref

Note that doing this gains you nothing in legibility.


Re: array reference

tamiry wrote:

Quoted text here. Click to load it

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,

-- /

The first rule of project mayhem is: you do not ask questions.
                              -- Fight Club

Re: array reference

thanks guys
I was trying
too. I got close, but not close enough untill now.

Re: array reference

Quoted text here. Click to load it

If it's a big list, you can save a list copy by modifying GetList to
return a reference to the list and pass that directly to ReadList. You
might want to change the names to GetListRef and ReadListRef, though.

   ReadListRef( GetListRef() );

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- The #1 Newsgroup Service in the World! >100,000
---= East/West-Coast Server Farms - Total Privacy via Encryption =---

Site Timeline