array reference

T

tamiry

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?
 
M

Mark Clements

tamiry said:
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
 
P

phaylon

tamiry said:
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
 
T

tamiry

thanks guys
I was trying
ReadList(\@[GetList])
too. I got close, but not close enough untill now.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top