Why does Perl's shift complain 'Type of arg 1 to shift must be array (not grep iterator).'?

Posted by wes on Stack Overflow See other posts from Stack Overflow or by wes
Published on 2010-03-28T22:05:05Z Indexed on 2010/03/29 15:03 UTC
Read the original article Hit count: 285

Filed under:
|
|

I've got a data structure that is a hash that contains an array of hashes. I'd like to reach in there and pull out the first hash that matches a value I'm looking for. I tried this:

   my $result = shift grep {$_->{name} eq 'foo'} @{$hash_ref->{list}};

But that gives me this error: Type of arg 1 to shift must be array (not grep iterator). I've re-read the perldoc for grep and I think what I'm doing makes sense. grep returns a list, right? Is it in the wrong context?

I'll use a temporary variable for now, but I'd like to figure out why this doesn't work.

© Stack Overflow or respective owner

Related posts about perl

Related posts about syntax