in reply to Re: File handle as a input variable
in thread File handle as a input variable

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>) { }

Replies are listed 'Best First'.
Re^3: File handle as a input variable
by lostjimmy (Chaplain) on May 06, 2009 at 00:58 UTC

    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.

Re^3: File handle as a input variable
by Marshall (Canon) on May 06, 2009 at 01:01 UTC
    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
        Don't pass strings