in reply to File handle as a input variable

open (my $File_Handle, "<", "some..path") or die "error msg";
Instead of \$Sample.txt , you need a path to a file. E.g. in the above, probably what you mean? is:
open (my $File_Handle, "<", "Sample.txt") or die (...blah ...);

Replies are listed 'Best First'.
Re^2: File handle as a input variable
by hem (Initiate) on May 06, 2009 at 00:51 UTC
    I tried that. But it does not work with use strict I get an error : Can't use string ("File_Handle") as a symbol ref while "strict refs" in use at Log_Preocessing.pl line 28. use strict; my $Sample = "C:\\Perl\\Ref.txt"; my $File_Handle = "File_Handle"; open $File_Handle, ">$Sample" or die "Cannot open $Sample.txt for read :$!"; print $File_Handle "hi"; while (<$File_Handle>) { }

      Do it exactly the way Marshall shows and it will work.

      The reason you are getting that error is because $File_Handle is not an "undefined scalar variable"". So instead of setting it beforehand to "File_Handle", declare it and set it in the call to open: open my $File_Handle.

      See open for more information on this.

      This: my $File_Handle = "File_Handle"; is wrong. delete that.

      for the open, put a valid path in there, like:
      open my $File_Handle, ">", "full_textual_path_to_a_file" or die ....
      Later use:
      print $File_Handle "some stuff\n";

        But I am getting the Fila Handle as a string argument How do i handle that thanks