in reply to passing a file handle to a subroutine

Personally, if I'm creating a subroutine whose purpose is to create a specific sort of file header, I would rather just have the subroutine return a single string value that is the file header, so that the caller can use the return value and does not need to pass around a file handle -- e.g.:
open( OUTPUT, ">", "some.file" ) or die "$!"; print OUTPUT rm3dHeader(); print OUTPUT rm3dData(); close OUTPUT; sub rm3dHeader { return "START_OF_FILE\n\nDATEFORMAT=YYYYMMDD\nDECIMALSEPARATOR=.\n +"; } sub rm3dData { return "this is the data\n"; }

This would provide some flexibility that might be handy, and generally helps to keep the "make_header" logic independent from the "create/write/close file" logic.

Replies are listed 'Best First'.
Re^2: passing a file handle to a subroutine
by Anonymous Monk on May 01, 2010 at 16:47 UTC
    Thanks.