On Tue, Jul 19, 2011 at 4:23 PM, Steven Surgnier <ssurgn...@gmail.com>wrote:
> Hi, > > I desire a concise conditional statement which simply checks if each entry > in an array matches a given string. For example: > > print "all the same" if (grep {m/test_name/} @bins) == scalar @bins); > > #END CODE > > I thought, "grep will return the number of matches, so why not just check > to > see if it equals the length of the array?" > I'm open to any suggestions even if it's merely cosmetic. > > Sincerely, > > Steven > use List::MoreUtils qw( all ); print "all the same" if all { /test_name/ } @bins; Which has the added bonus of stopping early if one of them doesn't match, while grep has to go through the entire array in either case.