in reply to Re: curly braces around a lexical file handle
in thread curly braces around a lexical file handle

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.

Replies are listed 'Best First'.
Re^3: curly braces around a lexical file handle
by ikegami (Patriarch) on May 31, 2010 at 04:08 UTC

    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;