"Mark J. Reed" <[EMAIL PROTECTED]> writes: > On 2003-01-07 at 11:31:13, Mr. Nobody wrote: >> .length is unneeded, since an array gives its length in numeric context, so >> you can just say +@a. > Unneeded, but harmless. > >> grep shouldn't be an array method either, it should be >> like the perl5 grep, as it is often used on lists, "grep /foo/, keys %h" is >> far more readable than "@{[keys %h]}.grep(/foo/)". > Didn't we already have the left-to-right vs. right-to-left discussion? > Regardless of how grep works when it's not invoked as a method, it > most definitely should be invokable as one on arrays. It would probably > be defined in a superclass rather than in Array itself, assuming Array > is a specific subclass of a more general collection class > (be it List or Collection or whatever), but that doesn't matter as long > as you can call it on an array. > > Also, some of the line noise in your "unreadable" example comes from your > mixing method syntax with other syntax. No need to do all that @{[keys %h]} > stuff - it would just be %h.keys.grep(/foo/), which looks pretty darn readable > to me.
Or, even %h.grep(-> $pair {.key =~ /foo/}) depending on what you actually want (assuming that grep treats %h as a list of pairs...)