snape has asked for the wisdom of the Perl Monks concerning the following question:

1. Is it possible to pass the same file handler as reference in two different subroutine ? Please Explain because I tried doing it and I wasn't successful.

2. What is disadvantage of having many file handlers passed to many subroutines ? Does it affects the efficiency of the program ?

Replies are listed 'Best First'.
Re: File Handler
by jwkrahn (Abbot) on Feb 01, 2010 at 07:16 UTC

      Those last two are rather dated, using a global variable for a file handle. They seem to talk a lot when for something that should only be one line of code:

      foo($fh);
Re: File Handler
by ikegami (Patriarch) on Feb 01, 2010 at 07:17 UTC

    They are "file handles".

    Is it possible to pass the same file handler as reference in two different subroutine ? Please Explain because I tried doing it and I wasn't successful.

    The reason you are having a problem is because you... Where's your code?

    What is disadvantage of having many file handlers passed to many subroutines ?

    None.

Re: File Handler
by rovf (Priest) on Feb 01, 2010 at 12:32 UTC
    Is it possible to pass the same file handler as reference in two different subroutine ?

    use FileHandle; sub f1 { my $handle=shift; ... } sub f2 { my $handle=shift; ... } my $fh=FileHandle->new(); ... f1($fh); f2($fh);

    What is disadvantage of having many file handlers passed to many subroutines ?
    Depends on your definition of the word many, on the operating system you are using, and whether or not the file handles point to open files. I recently stumbled over the problem, that on Windoze (if we want to call this an "operating system"), having a few hundreds of simultaneously open file handles caused the system to let me open a new one. This has, of course, nothing to do with passing them to *subroutines*.

    -- 
    Ronald Fischer <ynnor@mm.st>