Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > array reference

Reply
Thread Tools

array reference

 
 
tamiry
Guest
Posts: n/a
 
      05-24-2005
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?

 
Reply With Quote
 
 
 
 
Mark Clements
Guest
Posts: n/a
 
      05-24-2005
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
 
Reply With Quote
 
 
 
 
phaylon
Guest
Posts: n/a
 
      05-24-2005
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

 
Reply With Quote
 
tamiry
Guest
Posts: n/a
 
      05-24-2005
thanks guys
I was trying
ReadList(\@[GetList])
too. I got close, but not close enough untill now.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
const and array of array (of array ...) Mara Guida C Programming 3 09-03-2009 07:54 AM
Using an array to reference a different array Andrew Poulos Javascript 6 12-23-2008 02:58 PM
Length of Array of Array of Array Tom Perl Misc 3 12-20-2004 05:23 PM
Reference to array, NOT array of references! JKop C++ 12 07-21-2004 10:51 PM
Referring to a 'column' from a reference to an array of array references fatted Perl Misc 2 10-23-2003 03:22 PM



Advertisments