http://qs321.pair.com?node_id=857522

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

How do I print to a file from a sub routine when using strict subs?

I have a program that opens a file in the main portion of the code and then calls a sub that needs to print to the same file as well. I would like to avoid opening and closing the file every time I have to write to it.

In Java I would open the file in the main sub and then pass the file as an object to whatever sub nees to print to it.

ie:

public main(){ FileWriter file = new fileWriter(); file.open("file.txt"); print_sub(file); } private print_sub(FileWriter file){ //do something with the file }

is there a way to do this in Perl? thanks in advance