in reply to Replicate open() and close()

See perldoc perlsub, specifically the section entitled Prototypes. If you prototype them with sub my_open (*$) I think it should work the way you want. An alternative might be to use an OO interface and inherit from IO::Handle, just overriding the relevant methods.

Replies are listed 'Best First'.
Re: Re: Replicate open() and close()
by sauoq (Abbot) on Jan 29, 2003 at 22:52 UTC
    If you prototype them with sub my_open (*$) I think it should work the way you want.

    Close...

    $ perl -le 'print prototype("CORE::open")' *;$@
    -sauoq
    "My two cents aren't worth a dime.";
    
Re: Re: Replicate open() and close()
by BigLug (Chaplain) on Jan 29, 2003 at 22:56 UTC
    Thanks Fletch, I should have looked more in the docs .. they even call their example sub 'myopen'!:

    Declared as: sub myopen (*;$)
    Called as: myopen HANDLE, $name

      Declared as: sub myopen (*;$)

      Careful... The example in the docs won't do what you are asking for. It will complain about calling myopen() with 3 arguments. If you want it to act like perl's open(), use the same prototype that perl does. That's *;$@ as I pointed out in my reply to Fletch.

      perl -le 'sub myopen(*;$){print@_}myopen(FOO,"<","bar")' Too many arguments for main::myopen at -e line 1, at end of line Execution of -e aborted due to compilation errors.
      -sauoq
      "My two cents aren't worth a dime.";