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

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.
  • Comment on Re: Re: Re: First Unix Admin Script - Request for Constructive Critisism

Replies are listed 'Best First'.
Re: Re: Re: Re: First Unix Admin Script - Request for Constructive Critisism
by grantm (Parson) on Feb 09, 2003 at 02:55 UTC

    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.