Ashley, this is a great post. I have included it almost verbatim in my p6 talk I'm giving tomorrow at our Perl Monger's meeting:
http://www.metaperl.com/talks/p6/hangman-elucidated/slide6.html I hope you don't mind. > On 5/5/05, Terrence Brannon <[EMAIL PROTECTED]> wrote: >> I was looking at a line in the hangman program: >> >> @letters == @solution.grep:{ $_ ne '' }; >> >> and was told that I was looking at an adverbial block. >> >> But I don't understand what that is and could not find a description >> and examples in a reverse search on dev and nntp.perl.org. > > Methods with arguments require parens. However, the block to grep > isn't I<really> an argument. It's describing the manner in which the > array will be grepped... that's an adverb to grep. > > So, why are the parens required on methods? Take the following if statements: > > if @foo.shift { ... } > > if @foo.grep { ... } # grep doesn't get the block > > To make things clear, methods without parens are assumed to take no > arguments. In order to pass a block to the above grep, you either need > to use @foo.grep({ $^a <=> $^b}) or the adverbial colon: > > if @foo.grep:{$^a <=> $^b} { ... } > > Ashley Winters -- Carter's Compass: I know I'm on the right track when, by deleting something, I'm adding functionality.