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

I want to pass two files to a sub{}, then use these handles to process information within those files.
  • Comment on How do I pass two file names to a function

Replies are listed 'Best First'.
Re: How do I pass two file names to a function
by cacharbe (Curate) on Mar 11, 2002 at 03:31 UTC
    My first suggestions would be to look in perlman:perlfaq5 or even perlref.
    open (FILEHANDLEONE, "myfile1.txt") or die "couldn't open file\n"; open (FILEHANDLETWO, "myfile2.txt") or die "couldn't open file\n"; &SubName(\*FILEHANDLEONE,\*FILEHANDLETWO) or die "Couldn't do somethin +g : $!\n"; sub SubName{ my ($fhone, $fhtwo) = @_; while (<$fhone>){ #process file one } while (<$fhtwo>){ #process file two } return 1; }
    C-.
Re: How do I pass two file names to a function
by talexb (Chancellor) on Mar 11, 2002 at 03:30 UTC
    If you are trying to pass file handles to a subroutine, then
    open ( FILE_ONE, "foo.txt" ) || die "Unable to open foo: $!"; open ( FILE_TWO, "bar.txt" ) || die "Unable to open bar: $!"; CompareFiles ( \*FILE_ONE, \*FILE_TWO ); close ( FILE_TWO ); close ( FILE_ONE );
    will work fine. Once the file handle has reached the subroutine you can select it and read from it.

    Update: Removed reference to Algorithm::Diff; I mis-read the question to be referring to find 'differences' between two files.

    --t. alex

    "There was supposed to be an earth-shattering kaboom!" --Marvin the Martian