Oh, come on now. That would never work. If $red was true, you'd get all your tshirts, regardless of colour, while, if false, you'd be overdressed at the beach.
What I think you meant was: grep { $_->{colour} eq 'red' } @tshirts or, if you're an OO type of guy, grep { $_->colour() eq 'red' } @tshirts.
However, even that can get a bit messy. I mean, some of us have two, three, or even more, red shirts. Putting them all on at once would look silly, even for a computer geek. (Though, if you're in a workplace filled with perl geeks, you could do that one day - show up wearing all your red shirts, and if anyone asks why you're wearing so many shirts, just tell 'em that you did a grep { $_->has_colour('red') } @tshirts on your closet that morning...). Instead, what you really want is either use List::Utils qw/first/; first { $_->colour() eq 'red' } @tshirts or possibly my @reds = grep { $_->colour() eq 'red' }; $reds[rand @reds] depending on whether you want to be efficient or you prefer some variety.
Me? Too much perl? Nah ...
In reply to Re^2: Too Much Perl?
by Tanktalus
in thread Too Much Perl?
by apotheon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |