How to get a reference to a map function?

T

TonyV

Hopefully this is a really simple question.

I am using a map function to get an array, and I need to pass a
reference to that array to another function. Right now, this is
working:

# @queues is an array of anonymous hashes
my @q = map { $_->{name} } @queues;
do_something(\@q);

My question is this: Is there any way to skip assigning that
temporary variable and pass the result of the map function directly in
the do_something function call? Something like this:

# This is syntactically incorrect, but I need to pass the result of
the
# map function to do_something as an array *reference*, not an array.
do_something(\map { $_->{name} } @queues);

Thanks for any help!
 
P

Peter Makholm

TonyV said:
# This is syntactically incorrect, but I need to pass the result of
the
# map function to do_something as an array *reference*, not an array.
do_something(\map { $_->{name} } @queues);

do_something([ map { $_->{name} } @queues ]);

or even without parentheses

do_something [ map { $_->{name} } @queues ];

//Makholm
 
T

TonyV

TonyV said:
# This is syntactically incorrect, but I need to pass the result of
the
# map function to do_something as an array *reference*, not an array.
do_something(\map { $_->{name} } @queues);

do_something([ map { $_->{name} } @queues ]);

or even without parentheses

do_something [ map { $_->{name} } @queues ];

//Makholm

Awesome, that's perfect! Thanks a ton!
 

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

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,123
Latest member
Layne6498
Top