On Aug 23, 2012, at 1:58 PM, Chris Stinemetz wrote:

>> 
>> 
>> If @coords is just an Array of Arrays then that should be:
>> 
>> print grep { $_->[0] >= 0 } @coords;
>> 
>> 
>> Your example thinks @coords is an Array of Arrays of Arrays.
>> 
>> 
>> John
>> --
>> 
> 
> print grep { $_->[0] >= 0 } @coords;
> 
> Just prints the memory adress:
> ARRAY(0x29d459c)ARRAY(0x29d462c)ARRAY(0x29d46cc)
> 
> apparently I am not dereferencing the data structure correctly.

grep is a filter that will return any elements in @coords for which the test 
expression is true. While you have dereferenced the array-of-arrays to evaluate 
the expression, you will have to dereference it again to print the selected 
data.

It might be easiest to save the selected references:

  my @selected = grep { $_->[0] >= 0 } @coords;

then dereference the results:

  print $_->[0] for @selected;

You could also combine print, grep, and map to accomplish the same thing.


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to