in reply to Re: First Unix Admin Script - Request for Constructive Critisism
in thread First Unix Admin Script - Request for Constructive Critisism

One minor nit pick:

You don't test for success when you open MPCFG, and you open it without closing it. You could run out of open file handles

Filehandles are global (another good reason for preferring IO::File as you suggest) so if open is called with a FILEHANDLE argument that refers to an already open file, the FILEHANDLE is closed first. The original script might not be good style, but it doesn't leak filehandles.

  • Comment on Re: Re: First Unix Admin Script - Request for Constructive Critisism

Replies are listed 'Best First'.
Re: Re: Re: First Unix Admin Script - Request for Constructive Critisism
by D.Millin (Beadle) on Feb 08, 2003 at 21:13 UTC
    Thanks for the head up on IO:File. You mention that the script isn't good style. I would appreciate any advise, in this area, as I am just leveraging perl into what I have seen in ksh.

      The comment about style merely related to calling open() but not calling close(). In your script, it's really not a problem - each subsequent call to open() will close the previously opened file since the same filehandle is used each time. The last filehandle will be closed when the script exits.

      IO::File allows you to store your filehandle in a normal scalar - which is especially useful if you want to pass it to a subroutine. You would typically use a lexically scoped scalar (one declared with 'my') so that the filehandle was not global.

      Regardless of which form of open you use, as tall_man said, you should always check the return value and at the very least call die "$!" if it fails.