Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print to screen after writing to file 1

Status
Not open for further replies.

mbrosius

MIS
Apr 27, 2001
9
US
I am trying to print to the screen (STDOUT) after I write text to a file but it doesn't seem to work. The correct information is being written to my output file but if I want to display information on the screen it doesn't work. Here are snippets of my code:
#Read record from file
{
...
close (STDOUT);# close STDOUT in case it isn't closed yet.
open (STDOUT, '>-');
print "\n---------------------------------------------\n";
...
if ($SUCCESS eq "Y")
{
open (STDOUT, "+>>successful.log");
{
print "stuff is printed here\n";
}
close (STDOUT);
}
... #read next record from input file
 
Why are you using STDOUT as a file handle?
There are times when you might want to do that, but, they are fairly infrequent /rare.....probably not what you want to do here.
You can use any 'normal' string to name a file handle.
You can have multiple handles open at the same time.
So, you can leave STDOUT alone, and open a handle to your log. Print to the log as needed and print to STDOUT as needed.

Code:
open(OUTPUT_FILE,">>successful.log") 
     or die "Failed open, $!\n";
# print to output_file
print OUTPUT_FILE "Some Content for disk file\n";

# print to STDOUT
# since STDOUT is the default it is not explicitly named
print "This should go to the screen or something wacky is going on.\n";

# print another line to the log
print OUTPUT_FILE "More content for the log file.\n";

close OUTPUT_FILE;
'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Thanks for your suggestion. From what I have read I needed to use STDOUT as the filehandle because the information would have been displayed to the monitor and I wanted it to go to the file. I must have misunderstood my reading. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top