Loading ...
Sorry, an error occurred while loading the content.

How to pass a filehandle to a subroutine?

Expand Messages
  • hooyar66
    I am trying to pass a filehandle to a subroutine but cannot get the syntax right. I have been reading about using prototypes but something isn t sinking
    Message 1 of 1 , Jul 9, 2007
    • 0 Attachment
      I am trying to pass a filehandle to a subroutine but cannot get the
      syntax right. I have been reading about using 'prototypes' but
      something isn't sinking in... the test code below is the result of
      that research - it will not work with or without 'use strict' - I
      would prefer to keep 'strict'.

      Any help is gratefully appreciated

      Thanks
      NJH

      #!c:/perl/bin/perl.exe -w

      use strict;
      use diagnostics;

      open FH, ">mydat.txt";

      sub pass_fh(*);

      pass_fh(FH);

      sub pass_fh(*)
      {
      my $MYFILE = shift @_;
      print $MYFILE "Filehandle was passed!";
      }
    Your message has been successfully submitted and would be delivered to recipients shortly.