in reply to curly braces around a lexical file handle

The curly braces indicate a block. In your case, the curly braces are optional. But, in more complex cases, they are necessary. From the docs for print:
Note that if you're storing FILEHANDLEs in an array, or if you're using any other expression more complex than a scalar variable to retrieve it, you will have to use a block returning the filehandle value instead
  • Comment on Re: curly braces around a lexical file handle

Replies are listed 'Best First'.
Re^2: curly braces around a lexical file handle
by AnomalousMonk (Archbishop) on May 31, 2010 at 03:04 UTC
    In your case, the curly braces are optional.

    This is also a PBP-ism (#136). The general idea is always to do things in the same way even when unnecessary so no extra thought is needed (and no risk of forgetting is run) when it is necessary to do them in an unusual way.

    E.g., if you always write
        print {$filehandle} $some_data;
    even when you don't have to, no extra thought is needed when it comes time to write
        print {$hashref->{other}{handle}} $other_data;
    instead.

    Whether or not this approach is warranted in all cases is the subject of some debate.

      If that's true, you should be writing

      print( { $filehandle } $some_data );

      Running into problems from omitting those parens is far more likely than running into problem from omitting those curlies. Furthermore, omitting the curlies around the file handle expression when it's needed is likely to result in a compile-time error, whereas omitting parens can fail silently and subtly.

      If the argument you posted is valid, then it's far more important for

      print $filehandle $some_data;
      to be written as
      print($filehandle $some_data);
      than for it to be written as
      print { $filehandle } $some_data;