in reply to curly braces around a lexical file handle

A few functions take an expression in curlies as their first argument:
map ( { ... } ... ) grep ( { ... } ... ) print ( { ... } ... ) exec ( { ... } ... ) system ( { ... } ... )

In print's case,

In other words,

print $write_fh "$database_query";
is a shortcut for
print { $write_fh } "$database_query";

Replies are listed 'Best First'.
Re^2: curly braces around a lexical file handle
by JavaFan (Canon) on May 31, 2010 at 18:40 UTC
    Interestingly, in all cases, either the block is optional, or there's an alternative, non-block syntax:
    map EXPR, LIST; grep EXPR, LIST; print LIST; print BAREWORD LIST; print $HANDLE LIST; exec STRING; exec LIST; system STRING; system LIST;
    And some you missed, also have a non-block syntax:
    sort BLOCK LIST; sort SUBNAME LIST; sort LIST; eval BLOCK; eval STRING;
    Not sure whether there's a common issue behind this, or that it's just a coincidence.
      You missed do (which has a non-block syntax as well).
Re^2: curly braces around a lexical file handle
by Anonymous Monk on May 31, 2010 at 16:44 UTC
    Odd that the few special circumstances seem to be the vast majority of uses ;)
      I suspect that's exactly why they are special.