At 8:43 PM +0200 4/20/05, Juerd wrote:
Darren Duncan skribis 2005-04-20 11:40 (-0700):
 A clear way to disambiguate a block from a hash-ref when using
 map/grep/sort etc is to use a colon before the leading brace for a
 block rather than a space, like this:
    map:{ $_ => uc $_ }


I think the best disambiguators for hash/sub interpretation are "hash" and "sub", even though sub is a little longer than a colon. Juerd

In this case, I seem to recall reading that the problem was with the space, and the colon replaces the space.


The problem is that, with 'sort' for example, the block is optional, and I think it is like an adverb.

For example, this leaves it out:

  @bar = sort @foo;

In this case, it is kept:

  @bar = sort:{ $a <=> $b } @foo;

In both cases, @foo is the argument, and not the block. If you do 'sub' or etc, that would make this look like a code argument, which it isn't.

If you did this:

  @bar = sort { ... } @foo;

Then the {} would look like a first argument which is a hash ref.

The general principle of using the ':' was meant to work with any kind of list operator usage, to say how it does its thing, not with what.

-- Darren Duncan

Reply via email to