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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Printing to a File from Sub
by Corion (Patriarch) on Aug 26, 2010 at 17:51 UTC | |
Re: Printing to a File from Sub
by suaveant (Parson) on Aug 27, 2010 at 14:56 UTC | |
by PyrexKidd (Monk) on Aug 27, 2010 at 22:56 UTC | |
by choroba (Cardinal) on Aug 30, 2010 at 16:47 UTC | |
by pemungkah (Priest) on Aug 29, 2010 at 00:50 UTC | |
by choroba (Cardinal) on Aug 30, 2010 at 16:50 UTC | |
by suaveant (Parson) on Aug 30, 2010 at 19:33 UTC |
Back to
Seekers of Perl Wisdom