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

Let's say I need to read a file and if found another file in the contents, then read that file .. and so on recursively.

Is there a direct way to assign filehandle, and pass it as parameters to subroutine other than using typeglobs?

Please confirm!

Greets,
Hanny J

Replies are listed 'Best First'.
Re: Directly assigning Filehandle
by Joost (Canon) on May 04, 2005 at 15:57 UTC

      Unfortunately, the three argument open is not backwards compatible with 5.6.x. OTOH,
      open my $fh,"< $name" or die "can't open $name; $!";
      would work.

        5.6.x introduced both lexical filehandles and three-argument open.

Re: Directly assigning Filehandle
by ikegami (Patriarch) on May 04, 2005 at 16:02 UTC

    Or if you prefer OO notation,
    my $fh = IO::File->new($filename, 'r')

Re: Directly assigning Filehandle
by JediWizard (Deacon) on May 04, 2005 at 15:59 UTC

    you can use scalar variable to hold filehandles. See below:

    open(my $filehandle, '<', '/path/to/file') || die "$!\n";

    open


    They say that time changes things, but you actually have to change them yourself.

    —Andy Warhol

Re: Directly assigning Filehandle
by sh1tn (Priest) on May 04, 2005 at 16:02 UTC
    perldoc -q filehandle
    open my $fh, $file_name; open local $fh, $file_name; print $fh "Hello World!\n"; process_file( $fh );