Accessing elements in array ref of array references

F

fatted

Currently I'm comparing the first value of each of the array
references (which are stored in an array reference $ref_ref) as
follows:

if(map($_->[0] =~ /$keyword/i,@$ref_ref))
{
# Do something cunningly clever...
}

What I was wondering about (for no particular reason) is doing
something like:

if(map(/$keyword/i,cool_function(@$ref_ref, 0)))
{
# Do something equally cunningly clever...
}

Any idea's? (or should I get back to work ;)
 
F

Fatted

Greg Bacon said:
: [...]
:
: What I was wondering about (for no particular reason) is doing
: something like:
:
: if(map(/$keyword/i,cool_function(@$ref_ref, 0)))
: {
: # Do something equally cunningly clever...
: }
:
: Any idea's? (or should I get back to work ;)

If I understand you, cool_function would be equivalent to

sub cool_function {
my $i = pop;
map $_->[$i], @_;
}

We're discussing things at such a low level that we may be obscuring
an XY problem. What are you trying to do?

What I was interested in was keeping the map structure as I would normally
use it for mapping over a "normal" array and matching against $_ (eg
map(/$keyword/i,...), but mapping over the 0th element in each of the array
references which are stored in the array reference. Basically form an array,
which contains all the 0th elements of the array references, and then map
over it. If that makes sense :) I've no particular need to for this, but
just curiosity to see if I could form the map statement slightly
differently. (I think I'm forming an unhealthy fascination with map :)
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top